0

It should be easy to prevent "London" showing up at the top of the page, but I couldn't find how.

library(shiny)
ui <- fluidPage(
    mainPanel(
        mylist <- c("London","Paris"), 
        selectInput("s", "Select", mylist)
        )
    )
server <- function(input, output) {}
shinyApp(ui = ui, server = server)
armtar
  • 125
  • 12

2 Answers2

2

Take mylist out of fluidPage:

library(shiny)
mylist <- c("London","Paris")
ui <- fluidPage(
  mainPanel( 
    selectInput("s", "Select", mylist)
  )
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)

Otherwise mylist is included in the mainPanel function as another output to include such as a header.

Of course, as an alternative you could just include your option list directly in selectInput and omit the mylist vector completely:

selectInput("s", "Select", choices = c("London","Paris"))
Ben
  • 28,684
  • 5
  • 23
  • 45
  • thanks! I should have said that I have a pretty long code and I would like to keep "mylist" next to "selectinput", because they are part of the same module. – armtar Jun 23 '19 at 18:14
0

You can use the vector into direct inside selectInput like:

library(shiny)
ui <- fluidPage(
  mainPanel( 
    selectInput("s", "Select", choices = c("London","Paris"))
  )
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server) 

if you have to use some static validation in your option based on selection you can use something like:

library(shiny)
library(shinyalert)
ui <- fluidPage(
  mainPanel( 
    useShinyalert(),
    selectInput("option_select", "Select", choices = c("London"="lon","Paris"="par")),
    actionButton("check_city","City Selected")
  )
)
server <- function(input, output) {

  observeEvent(input$check_city,{
      if(input$option_select=="lon")
      {
       shinyalert("City Selected:  London")
      }
      else
      {
        shinyalert("City Selected:  Paris")
      }
  })
}
shinyApp(ui = ui, server = server)
Subhasish1315
  • 938
  • 1
  • 10
  • 25