r - 如何以编程方式将 R-Shiny “checkboxinput” 值更改为 FALSE/TRUE?
问题描述
我想在运行时将复选框输入值更改为 FALSE/TRUE。我怎样才能做到这一点?
checkboxInput(inputId = "smoother", label = "Overlay smooth trend line", value = FALSE)
解决方案
您可以使用updateCheckboxInput()
. 请参见下面的示例:
可重现的例子:
library(shiny)
ui <- fluidPage(
actionButton(
inputId = "check",
label = "update checkbox"
),
checkboxInput(
inputId = "checkbox",
label = "Input checkbox"
)
)
server <- function(input, output, session) {
observeEvent(
eventExpr = input$check, {
updatedValue = !input$checkbox
updateCheckboxInput(
session = session,
inputId = "checkbox",
value = updatedValue
)
}
)
}
shinyApp(ui, server)
推荐阅读
- entity-framework-core - 包含子查询的 Linq 在 EF Core 上失败
- entity-framework - 更新期间的实体框架错误:必填字段
- git - 如果设置了深度标志,Git 克隆或子模块更新找不到私钥文件
- ruby-on-rails - 使用 Kaminari 对迭代进行分页时遇到问题
- c++ - 如何在 VSCode 中构建和编译 C++?
- javascript - JavaScript 返回以及如何使用它来捕获错误
- swift - 将 SQLite 查询结果附加到现有模型
- shell - 无法在 sqlloader 中设置默认值
- c# - 使用 JObject.FromObject 序列化普通值和对象
- python - Pandas Groupby:如何获得不同的列值