I would like to create an simple app with reactive tabPanel/tabPanels which will depends on value in selectInput
(I already found a solution here). Furthermore, after I choose one value in this widget I will see different number of tabPanels which also should work as a filter.
E.g. in my app I use diamonds
dataset. If I choose a word 'Very Good' I will see a dataset with all rows with this value. In the top of it I will also see all unique color
values in filtered dataset. What I want to achieve is to get a possibility to filter once again using tabPanels above.
library(shiny)
library(shinyTree)
library(dplyr)
library(DT)
library(ggplot2)
diamonds_test <- sample_n(diamonds, 100)
diam_cut <-
list(
`Very Good` = "Very Good",
Ideal = "Ideal",
Fair = "Fair",
Premium = "Premium",
Good = "Good"
)
runApp(list(
ui = pageWithSidebar(
headerPanel('Dynamic Tabs'),
sidebarPanel(
selectInput('name','',choices = diam_cut)
),
mainPanel(
uiOutput('mytabs'),
dataTableOutput('table')
)
),
server = function(input, output, session){
output$mytabs = renderUI({
colorVector <- diamonds_test %>%
filter(cut == input$name) %>%
distinct(color) %>%
.[['color']] %>%
as.character()
myTabs = lapply(colorVector, tabPanel)
do.call(tabsetPanel, c(myTabs, type = 'pills'))
})
output$table <- renderDataTable({
data <- diamonds_test %>%
filter(cut == input$name)
datatable(data)
})
}
))