如何通过编程将R-Shiny的“ checkboxinput”值更改为FALSE / TRUE?

时间:2019-06-29 21:00:40

标签: r checkbox shiny

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

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

1 个答案:

答案 0 :(得分:1)

您可以使用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)