Hope this post helps someone learn Brilliant:
The information in the answers is useful conceptually and mechanically, but does not answer the general question.
So, the most useful function I found in the interface API is conditionalPanel() here
This means that I can create a slider function for each loaded dataset and get the maximum value by loading the data initially in global.R . For those who donβt know, objects loaded in global.R can reference ui.R
global.R - loads test data objects and objects (eset.spike and obatch) into ggplo2
source("profile_plot.R") load("test.Rdata")
server.R -
library(shiny) library(shinyIncubator) shinyServer(function(input, output) { values <- reactiveValues() datasetInput <- reactive({ switch(input$dataset, "Raw Data" = obatch, "Normalised Data - Pre QC" = eset.spike) }) sepInput <- reactive({ switch(input$sep, "Yes" = TRUE, "No" = FALSE) }) rangeInput <- reactive({ df <- datasetInput() values$range <- length(df[,1]) if(input$unit == "Percentile") { values$first <- ceiling((values$range/100) * input$percentile[1]) values$last <- ceiling((values$range/100) * input$percentile[2]) } else { values$first <- 1 values$last <- input$probes } }) plotInput <- reactive({ df <- datasetInput() enable <- sepInput() rangeInput() p <- plot_profile(df[values$first:values$last,], treatments=treatment, sep=enable) }) output$plot <- renderPlot({ print(plotInput()) }) output$downloadData <- downloadHandler( filename = function() { paste(input$dataset, '_Data.csv', sep='') }, content = function(file) { write.csv(datasetInput(), file) } ) output$downloadRangeData <- downloadHandler( filename = function() { paste(input$dataset, '_', values$first, '_', values$last, '_Range.csv', sep='') }, content = function(file) { write.csv(datasetInput()[values$first:values$last,], file) } ) output$downloadPlot <- downloadHandler( filename = function() { paste(input$dataset, '_ProfilePlot.png', sep='') }, content = function(file) { png(file) print(plotInput()) dev.off() } ) })
ui.R
library(shiny) library(shinyIncubator) shinyUI(pageWithSidebar( headerPanel('Profile Plot'), sidebarPanel( selectInput("dataset", "Choose a dataset:", choices = c("Raw Data", "Normalised Data - Pre QC")), selectInput("sep", "Separate by Treatment?:", choices = c("Yes", "No")), selectInput("unit", "Unit:", choices = c("Percentile", "Absolute")), wellPanel( conditionalPanel( condition = "input.unit == 'Percentile'", sliderInput("percentile", label = "Percentile Range:", min = 1, max = 100, value = c(1, 5)) ), conditionalPanel( condition = "input.unit == 'Absolute'", conditionalPanel( condition = "input.dataset == 'Normalised Data - Pre QC'", sliderInput("probes", "Probes:", min = 1, max = length(eset.spike[,1]), value = 30) ), conditionalPanel( condition = "input.dataset == 'Raw Data'", sliderInput("probes", "Probes:", min = 1, max = length(obatch[,1]), value = 30) ) ) ) ), mainPanel( plotOutput('plot'), wellPanel( downloadButton('downloadData', 'Download Data Set'), downloadButton('downloadRangeData', 'Download Current Range'), downloadButton('downloadPlot', 'Download Plot') ) ) ))