如何在Shiny中刷新或重置ui/form?
我在ui.R中有一个按钮:
actionButton("resetInput", "Reset inputs")
observeEvent(input$resetInput, { // refresh or reset the form })
我试过这个 answer ,但我得到了这个错误:
Warning: Error in library: there is no package called âshinyjsâ
这个包裹真的存在吗?
你应该把
library(shinyjs)
上面是您的服务器定义,您所指的示例中缺少该定义。
因此:
library(shinyjs) library(shiny) runApp(shinyApp( ui = fluidPage( shinyjs::useShinyjs(), div( id = "form", textInput("text", "Text", ""), selectInput("select", "Select", 1:5), actionButton("refresh", "Refresh") ) ), server = function(input, output, session) { observeEvent(input$refresh, { shinyjs::reset("form") }) } ))
我会修改你提到的答案,包括图书馆电话。希望这有帮助!