【问题标题】:Shiny - how to reset/ refresh the form?Shiny - 如何重置/刷新表单?
【发布时间】:2017-12-31 08:02:42
【问题描述】:

如何在 Shiny 中刷新或重置 ui/ 表单?

我在 ui.R 中有这个按钮:

actionButton("resetInput", "Reset inputs")

我应该在 server.R 中做什么来重置表单?

observeEvent(input$resetInput, {
   // refresh or reset the form      
})

我试过这个answer,但我得到了这个错误:

Warning: Error in library: there is no package called ‘shinyjs’

这个包真的存在吗?

在不安装新包的情况下有更好的方法吗?

【问题讨论】:

  • 包确实存在here is a link。我刚刚使用install.packages("shinyjs") 在我的机器上安装了它。您使用的是最新版本的 R 吗?
  • @MichaelBird 是的,我是。 R version 3.4.0 需要最新版本的R吗?
  • 根据 CRAN 它需要 R >3.1.0 所以这不是问题。该错误表明这是一个库问题,除此之外,我不知道。
  • 或者您可以使用updateSelectInputactionbutton 触发后重置值
  • @parth 有什么例子吗?

标签: r shiny shinyjs


【解决方案1】:

你应该放

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")
    })
  }
))

我将修改您所指的答案,使其还包括库调用。希望这会有所帮助!

【讨论】:

  • 感谢您的回答!
  • 没问题!如果它解决了您的问题,请考虑接受答案,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-11-29
  • 2022-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-17
  • 1970-01-01
相关资源
最近更新 更多