Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Create a data frame of which information is used in creating (dynamical) control widgets
- varnames <- names(iris[,1:4]) # names
- varinit <- apply(iris[,1:4],2,median) # initival value used in slider
- varmin <- apply(iris[,1:4],2,min) # min.
- varmax <- apply(iris[,1:4],2,max) # max.
- ## dataframe
- vardf <- data.frame(varnames,varmin,varmax,varinit)
- ui <- fluidPage(
- checkboxGroupInput("ConditioningVariables", "Conditioning variables (choose one or more):",
- varnames,inline = TRUE),
- uiOutput("ControlWidgetsofConditioningVariables"),
- tableOutput("data")
- )
- server <- function(input, output, session) {
- output$ControlWidgetsofConditioningVariables <- renderUI({
- if (is.null(input$ConditioningVariables)){
- return()
- } else {
- selvarnames = sort(input$ConditioningVariables)
- selpos = sapply(selvarnames,function(x) which(varnames==x))
- # create a taglist of dynamic widgets
- ListofDynamicWidgets <- lapply(selpos, function(x){sliderInput(as.character(vardf[x,1]),
- as.character(vardf[x,1]),
- vardf[x,2],vardf[x,3],
- vardf[x,4],.1)})
- do.call(tagList, ListofDynamicWidgets)
- }
- })
- ## filter data as per selected variables and their range
- ## this is where I'm kind of struck, I think I need to track number of variables (is list good idea?)
- ## and filter as per selected range of a specific variable
- newdata <- reactive({
- subset(iris)
- })
- output$data <- renderTable({ newdata() })
- }
- shinyApp(ui, server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement