Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interactive graphical data input in R

Tags:

r

shiny

Is it possible to do interactive and graphical user data input with R?`

I have a time vector t<-1:100 and I would like the user to supply graphically values of y.

Ideally I would like the interface to start with y<-rep(0, length(t)) have a do a plot(t,y, ylim=c(0,50), type="h") and I would like the user to draw at each t the height of y.

then use the graphically user supplied y vector to do some calculations.

Is this possible with R or should I turn to javascript? Can Shiny do this?

like image 961
ECII Avatar asked Apr 28 '26 17:04

ECII


1 Answers

If you want to do this natively in R (without opening Shiny, etc.) you can use the locator function, which will record the position of the mouse when clicking on the graphics device. Its first argument accepts a number of positions/clicks to record.

Here's a trivial example that updates your plot after each click:

t <- 1:5
y <- rep(0, length(t))
plot(t,y, ylim=c(0,50), type="h")
for(i in seq_along(t)){
    y[i] <- locator(1)$y
    plot(t,y, ylim=c(0,50), type="h")
}
like image 125
Thomas Avatar answered Apr 30 '26 10:04

Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!