如何更改R-Shiny的"checkboxinput"以编程方式将值设置为FALSE/TRUE? [英] How can I change R-Shiny "checkboxinput" value to FALSE/TRUE programmatically?

查看:40
本文介绍了如何更改R-Shiny的"checkboxinput"以编程方式将值设置为FALSE/TRUE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行时将checkboxinput值更改为FALSE/TRUE.我该怎么办?

I want to change the checkboxinput value to FALSE/TRUE during run-time. How can I do this?

checkboxInput(inputId = "smoother", label = "Overlay smooth trend line", value = FALSE)

推荐答案

您可以使用 updateCheckboxInput().请参见下面的示例:

You can use updateCheckboxInput(). See an example below:

可复制的示例:

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)

这篇关于如何更改R-Shiny的"checkboxinput"以编程方式将值设置为FALSE/TRUE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆