I anm trying to create a dropdown slicer in R studio before linking it into Power BI.
The code I have now has the logic that I want the slicer to have. But i'm not too sure how to change the settings of it to a dropdown interface. Can anyone help, Thank you!
library(shiny)
data <- data.frame(
ParentCode = c("A", "A", "B", "B", "C", "D", "D", "E", 'F'),
EntityCode = c("A1", "A2", "B1", "B2", "C1", "D1", "D2", "E1", "E2")
)
ui<-fluidPage(
selectInput("selected_entity", "Select Entity:", choices =
unique(data$EntityCode), multiple = TRUE),
verbatimTextOutput("selected_entities")
)
server <- function(input, output) {
observe({
filtered_data <- data[data$EntityCode %in% input$selected_entity, ]
output$selected_entities <- renderPrint({
paste("Selected Entities:", paste(input$selected_entity, collaspe = ", "))
paste ("ParentCodes:", unique(filtered_data$ParentCode))
})
})
}
shinyApp(ui,server)
If I correctly understand, you want something like that:
This is obtained as follows: