r - load a template in shiny -
question: there workaround how can simulate clicking of actionbutton within server code?
background: i've got shiny app quite few parameters user supposed type in. part of app divided several uis, each 1 created renderui. @ beginning, user sees first ui. once has filled in fields, supposed click on actionbutton , second ui dynamically generated, whereby fields , text of second ui depend on content of fields of first ui.
once user has filled in both uis, want able save content of fields template , load template next time use app. saving implemented writing values csv in structured way, , loading done update*-functions (such updatenumericinput, updatetextinput etc.).
the problem have somehow simulate clicking on actionbutton because @ time template loaded, second ui hasn't been created yet. doesn't add dependency on template upload button second ui, second ui needs values first one.
you can short javascript function makes call click() js function. here's short simple shiny app demonstrates how this.
library(shiny) library(shinyjs) jscode <- "shinyjs.click = function(id) { $('#' + id).click(); }" runapp(shinyapp( ui = fluidpage( useshinyjs(), extendshinyjs(text = jscode), actionbutton("btn1", "when click me, print time"), actionbutton("btn2", "when click me, i'll click other button") ), server = function(input, output, session) { observeevent(input$btn1, { print(sys.time()) }) observeevent(input$btn2, { js$click("btn1") }) } )) note i'm using shinyjs package make interacting js easy
Comments
Post a Comment