RStudio - set column as selectInput values

I have a table with the column "description" and a selectInput component. How can i set the column values from the table as the values to the selectInput?




To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one for a shiny app

hi, the thing is that i dont know exaclty the syntax how to set the column values as the selectInput values.

I have the selectIput:

selectInput("external", NULL, "Select external agent", NULL),

I can make a connection to the database, but how can i than use the columns?

In case you are still having issues with this, here is an example of the syntax.


# Dummy data simulating yours
df <- data.frame(stringsAsFactors = FALSE,
                 description = c("FER-01", "BGR-01", "ZUT-01"))

ui <- fluidPage(
    # Application title
            selectInput(inputId = "external", label =  NULL, choices = df$description)

server <- function(input, output) {
    output$selection <- renderText({
        paste("You have selected", input$external)

# Run the application 
shinyApp(ui = ui, server = server)

one more question:

I want to select not the whole table, but just the one attributes which are external Agent (set to 1).
Do you have a clue? where can i set the clausel?

If I understand you correctly, you just have to filter the dataframe like in this example:

selectInput(inputId = "external", label =  NULL, choices = df$description[df$isExternalAgent == 1])

Note: If you can't provide a reproducible example, at least provide sample data for your questions on a copy/paste friendly format, the screenshots are not very useful.
You can do it very easily with datapasta package, here is a nice blog post by Mara that explains how.

perfect - i just like R :slight_smile:

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