I am trying to filter and render a table in r shiny based of mutiple values from select input. The idea is the user can select multiple values from options 1.Select config
and one value from 2.Select var' . Based of this values it should filter that data from the table
testdataand render it in mainpanel. What The values in the dropdowns are nothing but a unique of strings from columns
configand
var`. Below is the code with the data.
library(shiny)
testdata <- tibble::tribble(
~config, ~construct, ~var,
"alpha,beta", "This is line 1", 12,
"beta,gamma,alpha", "This is line 2", 15,
"delta,alpha,tetra", "This is line 3", 21,
"quad,core ,delta", "This is line 4", 12,
"alpha,gamma", "This is line 5", 12,
"beta,core", "This is line 5", 11,
"delta,quad,tetra", "This is line 5", 21,
"quad,tetra", "This is line 5", 12
)
config <- unique(unlist(strsplit(as.character(testdata$config), ",")))
var <- unique(unlist(strsplit(as.character(testdata$var), ",")))
ui <- fluidPage(
title = 'Selectize examples',
sidebarLayout(
sidebarPanel(
selectizeInput(
'e2', '1.Select Config', choices = config, multiple = TRUE
),
selectizeInput(
'e3', '2. Select Var', choices = var, multiple = TRUE
),
br(),
actionButton('select', 'Select')
),
mainPanel(
width = 10,
DT::dataTableOutput(outputId = "mtable")
)
)
)
server <- function(input, output) {
filtered_year <- reactive({
filter(testdata, (config %in% input$e2) &
(var %in% input$e3) &
)
})
fully_filtered <- eventReactive(input$select, {
filtered_year()
})
output$mtable <- DT::renderDataTable({
DT::datatable(data = fully_filtered(), options = list(pageLength = 10),
rownames = FALSE, class = 'display', escape = FALSE)
})
output$ex_out <- renderPrint({
a <- str(sapply('e2', function(id) {
input[[id]]
}, simplify = FALSE))
a
print(a)
})
}
shinyApp(ui = ui, server = server)