将 selecInput 设置为未选择任何选项

Set selecInput to have no option selected

当运行应用程序时,您会看到Option 1已经被选中,但是很奇怪,因为在ui中我插入了selected="No option selected"。那我做错了什么?

我的想法是,当运行算法时,selectInput中没有选择选项。

下面的可执行代码:

library(shiny)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      fluidRow(
        column(
          width = 6,
          selectInput("test", label = h5("Choose"),choices = list("Option1 " = "1", "Option2" = "2", selected="No option selected")),
      ))),
    mainPanel(

    )
  )
)

server <- function(input, output, session) {
  
}

shinyApp(ui = ui, server = server)

一种方法是在 choices:

中放入一个空字符串
library(shiny)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      fluidRow(
        column(
          width = 6,
          selectInput("test", 
                      label = h5("Choose"),
                      choices = list("", "Option1 " = "1", "Option2" = "2"), 
                      selected=NULL),
        ))),
    mainPanel(
      
    )
  )
)

server <- function(input, output, session) {
  
}

shinyApp(ui = ui, server = server)