【发布时间】:2021-04-27 11:56:42
【问题描述】:
我的 Shiny 应用中有一个重置 (actionButton) 和更新按钮 (submitButton)。问题是要重置应用程序,我必须单击reset 按钮,然后单击update 按钮。是否可以在不点击更新的情况下重置应用?
编辑:我确实希望应用程序仅在用户明确单击更新后更新。这是因为在我的应用程序中,他们可以选择多个选择器来过滤数据。很高兴使用 submitbutton 以外的其他功能,但到目前为止,这是唯一可以达到此目的的功能。
在下面的示例中,我必须点击update 两次 才能重置整个应用程序:
library(shiny)
shinyApp(
ui = basicPage(
numericInput("num", label = "Make changes", value = 1),
submitButton("Update", icon("refresh")),
shinyjs::useShinyjs(),
actionButton("reset", "Reset"),
helpText(
"When you click the button above, you should see",
"the output below update to reflect the value you",
"entered at the top:"
),
verbatimTextOutput("value")
),
server = function(input, output) {
# submit buttons do not have a value of their own,
# they control when the app accesses values of other widgets.
# input$num is the value of the number widget.
output$value <- renderPrint({
input$num
})
observeEvent(input$reset, {
shinyjs::reset("num")
})
}
)
希望有人能赐教!
【问题讨论】:
-
包含提交按钮的应用程序不会在输入更改时自动更新其输出,而是等到用户明确单击提交按钮。通常不鼓励使用
submitButton,而是使用更通用的actionButton() -
谢谢I read this on the Shiny app site,但这正是我想要的;我想在点击更新之前选择几个过滤器,因为应用程序已经很慢了,所以我不希望它在每次选择过滤器时都做出反应。
-
同意@YBS,尽可能避免
submitButton。
标签: r shiny shinydashboard shinyjs