r - Shiny Reactivity -


i've got application large number of parameters. each parameters has lots of granularity make finding desired 1 pain. causes reactive portion calculate slows things down. added submitbutton solved above problem experience problem in turn.

below simple replication of framework build. parameter input takes in number 1 1000, indicates sample want. able above able resample same set of parameters. happening after adding submit button renders resample button inoperable unless click resample first , update button.

any ideas of making them both working separately?

shinyserver(function(input, output) {    gety<-reactive({     a<-input$gobutton     x<-rnorm(input$num)     return(x)   })    output$temp <-renderplot({      plot(gety())   }, height = 400, width = 400) })  shinyui(pagewithsidebar(   headerpanel("example"),   sidebarpanel(     sliderinput("num",             "number of samples",             min = 2,             max = 1000,             value = 100),     actionbutton("gobutton", "resample"),     submitbutton("update view")           ),     mainpanel(     tabsetpanel(             tabpanel("heatmap",                plotoutput("temp")       ),       tabpanel("about"),             id="tabs"     )#tabsetpanel         )#mainpane;    )) 

edit based on joe's answer:

shinyserver(function(input, output) {    gety<-reactive({      isolate({a<-input$gobutton       x<-rnorm(input$num)       return(x)})   })    output$temp <-renderplot({      b<-input$gobutton1      plot(gety())   }, height = 400, width = 400) })  shinyui(pagewithsidebar(   headerpanel("example"),   sidebarpanel(     sliderinput("num",             "number of samples",             min = 2,             max = 1000,             value = 100),     actionbutton("gobutton", "resample"),     actionbutton("gobutton1","update view")           ),     mainpanel(     tabsetpanel(             tabpanel("heatmap",                plotoutput("temp")       ),       tabpanel("about"),             id="tabs"     )#tabsetpanel         )#mainpane;    )) 

the answer given joe cheng in comment above, seeing op had difficulty understanding it, write out explicitly below, record:

# ui.r  library("shiny") shinyui(   pagewithsidebar(     headerpanel("example")     ,     sidebarpanel(       sliderinput("n", "number of samples", min = 2, max = 1000, value = 100)       ,       actionbutton("action", "resample")     )     ,       mainpanel(       tabsetpanel(               tabpanel("plot", plotoutput("plotsample"))         ,         id = "tabs1"       )     )   ) )  # server.r  library("shiny") shinyserver(   function(input, output, session) {      data <- reactive({         input$action         isolate({              return(rnorm(input$n))             return(x)         })     })   output$plotsample <-renderplot({       plot(data())     } , height = 400, width = 400   ) }) 

note having input$action inside reactive(), "action" actionbutton's inputid, enough trigger new rendering of plot. need 1 actionbutton.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -