Last active
August 29, 2015 14:19
-
-
Save meowcat/5c4f80a9b173e56bcc22 to your computer and use it in GitHub Desktop.
This file contains 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
server <- function(input, output, session) { | |
# Insert the right number of plot output objects into the web page | |
output$plots <- renderUI({ | |
r.y <- lapply(1:input$panel.y, function(panels.y) | |
{ | |
r.x <- lapply(1:input$panel.x, function(panels.x) | |
{ | |
plotname <- paste("plot",panels.x,panels.y, sep="-") | |
clickname <- paste(plotname, "click", sep="-") | |
column(width= 12/input$panel.x, plotOutput(plotname, height=input$panel.h, width=input$panel.w, | |
clickId=clickname)) | |
}) | |
do.call(fixedRow, r.x) | |
}) | |
#do.call(tagList, r.x) | |
}) | |
# The actual plotting function | |
observe({ | |
# replot on change of panel settings | |
input$panel.x | |
input$panel.y | |
# replot on selecting a new compound | |
input$cpd | |
row <- as.integer(input$cpd) | |
for(panels.y in 1:input$panel.y) { | |
for(panels.x in 1:input$panel.x) { | |
local({ | |
inputname <- paste("file",panels.x,panels.y, sep="-") | |
plotname <- paste("plot",panels.x,panels.y, sep="-") | |
output[[plotname]] <- renderPlot({ | |
plot.new() | |
title(main=paste(inputname, row)) | |
}) | |
}) #local | |
} # for panels.x | |
} # for panels.y | |
}) # observe | |
# catch the clicks on every plot. | |
observe({ | |
input$panel.y | |
input$panel.x | |
# # Make an observer for the clickId for every single plot! | |
# for(panels.y in 1:input$panel.y) { | |
# for(panels.x in 1:input$panel.x) { | |
# plotname <- paste("plot",panels.x,panels.y, sep="-") | |
# clickname <- paste(plotname, "click", sep="-") | |
# input[[clickname]] | |
# } | |
# } | |
l <- list() | |
# Make an observer for the clickId for every single plot! | |
for(panels.y in 1:input$panel.y) { | |
for(panels.x in 1:input$panel.x) { | |
plotname <- paste("plot",panels.x,panels.y, sep="-") | |
clickname <- paste(plotname, "click", sep="-") | |
print(clickname) | |
# Observe the clickId for every plot (note: this is a nested observer because otherwise we don't know where the click came from!) | |
l[[clickname]] <- observe({ | |
input[[clickname]] | |
print(clickname) | |
print(input[[clickname]]) | |
}) | |
} | |
} | |
return(l) | |
}) | |
} | |
ui <- fluidPage( | |
sidebarLayout( | |
sidebarPanel( | |
selectInput("cpd", "Compound", 1:100, 1) | |
), | |
mainPanel( | |
tabsetPanel( | |
tabPanel("View", | |
uiOutput("plots") | |
), | |
tabPanel("Setup", | |
sliderInput("panel.x", "Horiz. panels", 1,8,3), | |
sliderInput("panel.y", "Vert. panels", 1,8,3), | |
sliderInput("panel.w", "Panel width", 250,600,300), | |
sliderInput("panel.h", "Panel height", 250,600,300) #, | |
#uiOutput("plotMapping") | |
) | |
) | |
) | |
) | |
) | |
shinyApp(ui = ui, server = server) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment