How can I change R-Shiny “checkboxinput” value to FALSE/TRUE programmatically?

南笙酒味 提交于 2021-01-29 05:30:16

问题


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)

回答1:


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

Reproducible example:

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)


来源:https://stackoverflow.com/questions/56820844/how-can-i-change-r-shiny-checkboxinput-value-to-false-true-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!