Created
May 21, 2014 18:56
-
-
Save mplourde/0da40bd84ddf946c921d to your computer and use it in GitHub Desktop.
dynamic panels 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ui <- fluidPage( | |
fileInput('file', 'File'), | |
selectInput('col_select', 'Columns', choices=c(''), multiple=TRUE), | |
wellPanel(uiOutput('wellpanels')) | |
) | |
server <- function(input, output, session) { | |
data <- reactive({ | |
f <- input$file | |
if (! is.null(f)) | |
read.csv(f$datapath) | |
}) | |
observe({ | |
d <- data() | |
if (! is.null(d)) | |
updateSelectInput(session, 'col_select', choices=names(d)) | |
}) | |
output$wellpanels <- renderUI({ | |
d <- data() | |
if (! is.null(d)) { | |
lapply(names(d), function(col) { | |
range.col <- range(d[[col]]) | |
conditionalPanel(condition=paste0('output.panels["', col, '"]'), | |
wellPanel( | |
sliderInput(paste(col, 'slider', sep='_'), strong(col), | |
min=range.col[1], max=range.col[2], value=range.col) | |
) | |
) | |
}) | |
} | |
}) | |
output$panels <- reactive({ | |
d <- data() | |
as.list(setNames(names(d) %in% input$col_select, names(d))) | |
}) | |
outputOptions(output, 'panels', suspendWhenHidden=FALSE) | |
} | |
runApp(list(ui=ui, server=server)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment