r - 取消选中框,但可以重新选中 R Shiny
问题描述
在我正在开发的闪亮应用程序中,有一个复选框,当我单击操作按钮时,我想将其重置为关闭。我发现当我单击按钮时取消选中该框的代码,但随后该按钮永久保持未选中状态,我无法重新选中它。有谁知道如何在按下按钮后取消选中该框,同时保持选中该框的能力?
以下是我已经尝试过的一些遇到上述问题的尝试:
ui <- fluidPage(
# Application title
titlePanel("Preflop Trainer"),
sidebarLayout(
sidebarPanel(
checkboxInput("checkbox",
"Check Box"),
actionButton("reset",
"Reset the box")
)
)
server <- function(input, output,session) {
#I tried this
if (input$reset) {
if (input$reset != number) {
updateCheckboxInput(session,"checkbox","Check Box",value = F)
}
number <- input$reset
}
#And I've tried this
observeEvent(input$reset, {
updateCheckboxInput(session,"checkbox","Check Box",value = F)
}
}
解决方案
请再试一次。在纠正了一些括号问题后,这对我有用:
library(shiny)
ui <- fluidPage(
# Application title
titlePanel("Preflop Trainer"),
sidebarLayout(mainPanel =
mainPanel(),
sidebarPanel =
sidebarPanel(
checkboxInput("checkbox",
"Check Box"),
actionButton("reset",
"Reset the box")
)
)
)
server <- function(input, output,session) {
#this works for me
observeEvent(input$reset, {
updateCheckboxInput(session, "checkbox", "Check Box", value = F)
}
)
}
shinyApp(ui, server)
推荐阅读
- swift - 为什么我不能在通知中传递带有枚举键的字典
- jquery - Django:即使没有任何改变,Jquery 也不会突然工作.. .. 没有定义
- javascript - 是否可以从 onkeyup 获取密钥代码?
- python - 无法导入 numpy:AttributeError:类型对象“numpy.ndarray”没有属性“__array_function__”
- git - 你如何调试 git 凭证助手?
- matlab - 使用 for 循环和 fsolve 的非线性方程
- github - GitHub Actions:过滤器返回“jq:错误无法迭代 null (null)”
- php - PHP致命错误:未捕获的错误:在布尔值上调用成员函数execute()
- sql-server - 我应该在 SSIS 中的 ADO.Net 和 OLE 之间选择什么?
- laravel - Laravel 背包列表不显示