繁体   English   中英

在Shiny中,我只想在UI加载期间一次updateSelectInput()

[英]In Shiny I want to updateSelectInput() only once during UI load

我有一个下拉列表(SelectInput),我只想更新一次,并在上传UI时以编程方式将其加载到项目列表中。 我将其放在Render函数中,但问题是它一次又一次地重置。

selectInput具有允许您设置初始状态的参数。 在这些参数中,你可以使用choices提供选项,并selected具有默认值。 请运行?shiny::selectInput了解更多详细信息。

如果要在响应上下文中用户交互时对其进行更新,则在server端呈现它或最好使用updateSelectInput呈现将updateSelectInput

这是一个最小的示例:

library(shiny)

ui <- fluidPage(
  selectInput(
    inputId = "digits_input", 
    label = "Digits:", 
    choices = 0:9
    ## other arguments with default values:
    # selected = NULL,
    # multiple = FALSE,
    # selectize = TRUE, 
    # width = NULL, 
    # size = NULL
  ),

  selectInput(
    inputId = "letters_input", 
    label = "Lower case letters:", 
    choices = letters,
    selected = c("a", "b", "c"), # initially selected items 
    multiple = T # to be able to select multiple items
  ),

  actionButton(
    inputId = "update",
    label = "Capitalize"
  )

)

server <- function(session, input, output) {
  observeEvent(input$update, {
    updateSelectInput(
      session,
      inputId = "letters_input",
      label = "Upper case letters:",
      choices = LETTERS,
      selected = c("A", "B", "C")
    )
  })
}

shinyApp(ui = ui, server = server)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM