Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Set selecInput to have no option selected

When running the app, you will see that Option 1 is already selected, however it is strange because in ui I inserted selected="No option selected". So what am I doing wrong?

My idea is that when running the algorithm, there is no option selected in selectInput.

Executable code below:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

enter image description here

>Solution :

One way is to put an empty string in 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)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading