selectInput: "selected" is not working

I there! I wanted to see if anyone can help me with the selected output. I cannot make it work. It only Works when I give it "choices" like:
choices=c("confirmed", "deaths", "recovered"), selected="confirmed"

But when the "choices" are element of a dataframe column, selected is not working.
Here is my code for User Interface. I know you can´t check it in your consoles because you don´t have the csv, but maybe you can see my error in the code:

ui <- fluidPage(
titlePanel(h1(strong("5. Country Evolution"), align = "center")),

                    "Please, before using the application, choose a country:", 
                    choices = coronavirus_daily$Country.Region,
                    selected = "Spain"

It appears that(with any country selected):

And I want to be plotted that when I run the app:

Thank ypu very much in advance!


Can you provide evidence that coronavirus_daily$Country.Region is a character vector containing "Spain" as one of its elements?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

can you try this reprex and let me know if it 'works' for you or not ?

(t1 <- tribble( ~cr,~ofact, 

(tfact1 <- t1 %>% mutate(cr = factor(cr)) )

(tfact2_g <- group_by(tfact1, ofact))


ui <- fluidPage(
  selectInput(inputId = "si_1",
              label = "ungrouped",
              choices = unique(tfact1$cr),
              selected = "Spain"),
  selectInput(inputId = "si_2",
              label = "grouped",
              choices = unique(tfact2_g$cr),
              selected = "Spain")

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

shinyApp(ui, server)

Yes of course. Here we go. If you need anything else just tell me:



I think you simply need to wrap the choices with unique() like in my example.
if I remove that from my reprex, (dont use unique) I get the original issue you raised

1 Like

Yes! This is what I´ve got:

OMG I did it! It is working now!

Thank you very much for your heeelp!!


1 Like