Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. ## Create a data frame of which information is used in creating (dynamical) control widgets
  2. varnames <- names(iris[,1:4]) # names
  3. varinit <- apply(iris[,1:4],2,median) # initival value used in slider
  4. varmin <- apply(iris[,1:4],2,min) # min.
  5. varmax <- apply(iris[,1:4],2,max) # max.
  6.  
  7. ## dataframe
  8. vardf <- data.frame(varnames,varmin,varmax,varinit)
  9.  
  10. ui <- fluidPage(
  11. checkboxGroupInput("ConditioningVariables", "Conditioning variables (choose one or more):",
  12. varnames,inline = TRUE),
  13. uiOutput("ControlWidgetsofConditioningVariables"),
  14. tableOutput("data")
  15. )
  16.  
  17. server <- function(input, output, session) {
  18.  
  19. output$ControlWidgetsofConditioningVariables <- renderUI({
  20. if (is.null(input$ConditioningVariables)){
  21. return()
  22. } else {
  23. selvarnames = sort(input$ConditioningVariables)
  24. selpos = sapply(selvarnames,function(x) which(varnames==x))
  25. # create a taglist of dynamic widgets
  26. ListofDynamicWidgets <- lapply(selpos, function(x){sliderInput(as.character(vardf[x,1]),
  27. as.character(vardf[x,1]),
  28. vardf[x,2],vardf[x,3],
  29. vardf[x,4],.1)})
  30. do.call(tagList, ListofDynamicWidgets)
  31. }
  32. })
  33. ## filter data as per selected variables and their range
  34. ## this is where I'm kind of struck, I think I need to track number of variables (is list good idea?)
  35. ## and filter as per selected range of a specific variable
  36. newdata <- reactive({
  37. subset(iris)
  38. })
  39. output$data <- renderTable({ newdata() })
  40. }
  41. shinyApp(ui, server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement