Created
May 21, 2014 18:19
-
-
Save mplourde/fda063e5e8789ae959ab to your computer and use it in GitHub Desktop.
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( | |
tags$script(' | |
Shiny.addCustomMessageHandler("toggleWellPanel", | |
function(message) { | |
document.getElementById(message["id"]).style.display = message["status"]; | |
} | |
); | |
'), | |
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)) { | |
panels <- lapply(names(d), function(col) { | |
range.col <- range(d[[col]]) | |
div(class='measure_well', id=paste(col, 'panel', sep='_'), | |
wellPanel( | |
sliderInput(paste(col, 'slider', sep='_'), strong(col), | |
min=range.col[1], max=range.col[2], value=range.col) | |
) | |
) | |
}) | |
#do.call(wellPanel, panels) | |
#do.call(wellPanel, c(list(tags$style('.measure_well {display: none;}')), panels)) | |
c(list(tags$style('.measure_well {display: none;}')), panels) | |
} | |
}) | |
observe({ | |
d <- isolate(data()) | |
selected <- input$col_select | |
for (col in names(d)) { | |
status <- if (col %in% selected) 'block' else 'none' | |
session$sendCustomMessage(type='toggleWellPanel', list(id=paste(col, 'panel', sep='_'), status=status)) | |
} | |
}) | |
} | |
runApp(list(ui=ui, server=server)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment