3

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?

1 Answer 1

3

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")
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.