Advertisement
swchen

renderUI_help

Aug 3rd, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.59 KB | None | 0 0
  1. library(shiny)
  2. demo=data.frame(
  3.    brand=c("a","a","a","a","a","a","b","b","b","b","b","c","c","c","c","c"),
  4.    model=c("a11","a11","a21","a21","a31","a31","b55","b55","b56","b56","b56","c33","c34","c34","c33","c34"),
  5.    tax=c("y","x","y","x","x","y","x","x","x","y","y","x","y","x","y","y"),
  6.    seller=c("A","B","B","C","C","D","A","D","B","C","D","B","A","C","C","D"),
  7.    price=c(1000,1100,1500,1400, 1200,   1300,   2000,   2200,   1900,   1800,   1700,   800,    900,    850,    950,    880),stringsAsFactors = F
  8. )
  9. runApp(list(
  10.    
  11.    ui = shinyUI(fluidPage(
  12.          titlePanel("dynamic renderUI test"),
  13.          sidebarLayout
  14.          (
  15.          sidebarPanel
  16.          (width=3,
  17.          selectInput("brand",label="my dynamic brand",choices=c("all","a","b","c"),selected="all"),
  18.          uiOutput("ui1"),
  19.          uiOutput("ui2"),
  20.          uiOutput("ui3")
  21.          ),
  22.          
  23.          mainPanel
  24.          (
  25.          navbarPage(
  26.             title="",
  27.             tabPanel("dynamic table test",dataTableOutput("table"))
  28.          )
  29.          )
  30.          )))
  31.    
  32. , server = function(input, output) ({
  33.    output$ui1=renderUI({
  34.       selectInput("model","select the model",choices=c("all",sort(unique(demo[demo$model==input$model]$model))))
  35.    })
  36.    
  37.    output$ui2=renderUI({
  38.       selectInput("tax","select the tax",choices=c("all",sort(unique(demo[demo$tax==input$tax]$tax))))
  39.    })
  40.    
  41.    output$ui3=renderUI({
  42.       selectInput("seller","select the seller",choices=c("all",sort(unique(demo[demo$seller==input$seller]$seller))))
  43.    })
  44.    
  45.    output$table=renderTable({
  46.       demo
  47.    })
  48.       })
  49.   )
  50. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement