I have the shiny app below in which the user may select between one or more column names from the data frame.
name<-c("John","Jack","Bill")
value1<-c(2,4,6)
add<-c("SDF","GHK","FGH")
value2<-c(3,4,5)
dt<-data.frame(name,value1,add,value2)
Then for every selection he makes the relative pickerInput()
may be displayed below. Maybe I could use if
for every case but the issue is that my real dataset may be much bigger and has different column names every time so Im looking for a way to instantly connect the pickerInput()
selected name with the creation of the relative pickerInput()
which will include the column values. For example if someone select all 4 column names 4 pickerInput()
should be created with the relative column name as label.
My method is the insertUI
method but I have to find a way to create widget with different choices and label every time and also remove it when de-select the relative value of the 1st pickerInput()
.
library(shiny)
library(shinyWidgets)
library(DT)
# ui object
ui <- fluidPage(
titlePanel(p("Spatial app", style = "color:#3474A7")),
sidebarLayout(
sidebarPanel(
pickerInput(
inputId = "p1",
label = "Select Column headers",
choices = colnames( dt),
multiple = TRUE,
options = list(`actions-box` = TRUE)
)
),
mainPanel(
)
)
)
# server()
server <- function(input, output) {
observeEvent(input$p1, {
insertUI(
selector = "#p1",
where = "afterEnd",
ui = pickerInput(
inputId = #The colname of selected column
,
label = #The colname of selected column
,
choices = #all rows of selected column
,
multiple = TRUE,
options = list(`actions-box` = TRUE)
)
)
})
}
# shinyApp()
shinyApp(ui = ui, server = server)