I have a list l of data.frames, and I want to dynamically select elements with selectInput.
Once the user selects an element, I'd like to be able work with it under the hood, for example use it in renderTable and output a table of that data.frame.
Moreover I'd like to be able to select that element in the list, and apply lm for example.
The problem I'm facing is here: l[[ElemInput()]] how do I convert this classic R code with a reactive element?
Here the complete shinydashboard:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(
title = "My Dashboard"
),
dashboardSidebar(
sidebarMenu(
menuItem("aaa", tabName = "aaa", icon = icon("dashboard"))
)
),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "aaa",
h2("Dashboard aaa"),
fluidRow(
box(
selectInput("input_name", "Select input:", choices = names(l))
),
box(
dataTableOutput('table')
)
)
)
)
)
)
server <- function(input, output) {
# create a fake list
set.seed(123)
l <- list(element1 = data.frame(aaa=1:5, bbb=sample(5)),
element2 = data.frame(ccc=6:10, ddd=sample(5)))
# reactive read element
ElemInput <- reactive({
input$input_name
})
# render table
output$table <- renderTable({
l[[ElemInput()]] # this part doesn't work
})
}
shinyApp(ui, server)
Possibly correlated questions but I couldn't figure out a solution for my case:
dynamically list 'choices' for selectInput from a user selected column