Interactive graphical input in R
Can interactive and graphical user data be done with R? `
I have a time vector t<-1:100
and I would like the user to display graphical values y
.
Ideally, I would like the interface to start with y<-rep(0, length(t))
and then, and I would like the user to draw at every t height y
.
then use a graphically custom vector y
to do some calculations.
Is this possible with R or should I switch to javascript? Can Shiny do it?
source to share
If you want to do this natively in R (without opening Shiny, etc.), you can use a function locator
that will record the position of the mouse when you click on the graphics device. Its first argument takes multiple positions / clicks to write.
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")
}
source to share