I am trying to create an app where you are able to select the columns that you want to see.
This post helped me a lot: Shiny How to dynamically select columns of imported dataset for further analysis
However, I want to be able to select the columns if the user doesn't click on the options and writes the columns who wants to see.
Right now, in order to be able to select columns you need to click or write ONE column.
However when you try to write more than 1 column (like this: "cyl mpg hp", in the same line) it doesn't appear anything.
This is the code:
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("select", "Select columns to display", c('col1,col2'), multiple = TRUE),
actionButton("update", "Update Data set", class = "btn-primary",style='padding:4px; font-size:120%')
),
# Show a plot of the generated distribution
mainPanel(
h2('The Mydata'),
#tableOutput("mytable")
DT::dataTableOutput("mytable")
)
)
)
library(shiny)
library(DT)
server <- function(session, input, output) {
data <- reactive({
mtcars
})
filtereddata <- eventReactive({
input$update
data()
}, {
req(data())
if(is.null(input$select) || input$select == "")
data() else
data()[, colnames(data()) %in% input$select]
})
observeEvent(data(), {
updateSelectInput(session, "select", choices=colnames(data()))
})
output$mytable <- renderDataTable(filtereddata())
}
# Run the application
shinyApp(ui = ui, server = server)
I have tried doing in another way, like here: https://shiny.rstudio.com/reference/shiny/1.6.0/varSelectInput.html but I have the same problem.
Thanks in advance
Regards