Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- df <- data.frame(id = c("1","1","1","1","1","1","2","2","2","2"),
- brand = c("w","w","w","s","s","s","w","w","w","s"),
- model =
- c("w123","w123","w456","s99","s88","s88","w123","w456","w456","s99"),
- amount = c(10,9,7,8,6,4,7,3,2,8))
- df$id=as.character(df$id)
- df$brand=as.character(df$brand)
- df$model=as.character(df$model)
- app = shinyApp(
- ui = shinyUI(fluidPage(
- titlePanel("hirearchy data group"),
- sidebarLayout
- (
- sidebarPanel
- (
- selectInput("brand",label="choice the brand",choices=c("all","w","s")),
- selectInput("model",label="choice the model",choices=c("all","w123","w456","s99","s88"))
- ),
- mainPanel
- (
- dataTableOutput("table")
- )
- ))),
- server = function(input, output, session) {
- output$table <- renderDataTable({
- if(input$brand!="all") {df=df[which(df$brand==input$brand),]}
- if(input$model!="all") {df=df[which(df$model==input$model),]}
- df
- })
- models = observe({
- input$brand
- if (input$brand=="all"){
- choice = c("all", unique(df$model))
- }else{
- choice = c("all", unique(df[df$brand==input$brand,]$model))
- }
- updateSelectInput(session, "model", choice = choice)
- })
- }
- )
- runApp(app)
Advertisement
Add Comment
Please, Sign In to add comment