r - Automating Interaction with RShiny App -
i trying automate interaction of shiny app displays series of results while incrementing through predetermined range of inputs, without having repetitiously count , change input values. automation provide systematic view of set of inputs, such displays of refreshed price charts selected stocks, or plots of current performance indicators real-time processes being monitored.
this similar question [update graph/plot fixed interval of time] (update graph/plot fixed interval of time) runs loop timer. extending approach, objective to: a) automatically set invalidatelater pause high (1 hour) stop cycle after fixed (5) set of displays, pending new user input restart it.
b) [when can that, add counter-based control cycle through set of input$obs before stops. simplicity, step, has same error , presumably same solution, omitted here.]
using above referenced toy example, following script repeatedly cycle through 5 displays, yields error rather changing pause interval.
listening on port 8100 error in hist.default(dist, main = paste("last histogram count =", as.numeric(updater()), : 'x' must numeric
as.numeric(autocontrol()) error: not find function "autocontrol"
i can not find reactive conductor, reactivevalues or other methods task requires. thank help.
library(shiny) updates <- 0 updater <- function(){ updates + 1 } runapp(list( ui = pagewithsidebar( headerpanel("hello shiny!"), sidebarpanel( sliderinput("obs", "number of observations:", min = 1, max = 1000, value = 50) , selectinput(inputid = "secpause", label = "seconds between displays:", choices = c(1, 2, 3, 60*60), selected = 2) ), mainpanel( plotoutput("distplot") ) ), server =function(input, output, session) { updatetracker <- reactive( { invalidatelater(as.numeric(input$secpause) * 1000, session) updates <<- as.numeric(updater()) }) autocontrol <- reactive( { if(updatetracker() <= 5) secpause <<- input$secpause else secpause <<- 60*60 return(secpause) }) output$distplot <- renderplot( { if(updatetracker() <= 5) { # generate rnorm distribution , plot dist <- rnorm(input$obs) hist(dist, main = paste("histogram count =" , updatetracker())) } else { updates <<- 0 hist(dist, main = paste("last histogram count =", as.numeric(updater()), "with secpause =", as.numeric(autocontrol()))) } }) } ))
you getting error because hist distribution defined inside if clause, using (after 5 intervals) inside else clause, not defined. that's why works first 5 intervals.
if(updatetracker() <= 5) { # generate rnorm distribution , plot dist <- rnorm(input$obs) hist(dist, main = paste("histogram count =" , updatetracker())) } else { updates <<- 0 hist(dist, main = paste("last histogram count =", as.numeric(updater()), "with secpause =", as.numeric(autocontrol()))) } after moved dist before if condition, got cycling work. (i split code ui.r , server.r make more manageable.) not pasting here since same code, can find working version of code in gist.
Comments
Post a Comment