Here is functional code to make a variable number of plots based on the number of columns. I suggest using this as a starting point, and adding small amounts of code until you pinpoint what exactly is breaking it.
server.r:
max_plots <- 100
library(shinyIncubator)
shinyServer(function(input, output) {
sampletable=reactive({
if(input$go<1)
return()
x1=c(106:110, 21:25)
x2=c(101:105, 201:205)
x3=c(21:25, 31:35)
x4=c(51:60)
input$go
x=isolate(rbind(x1,x2,x3,x4))
x
})
# Insert the right number of plot output objects into the web page
output$plots <- renderUI({
plot_output_list <- lapply(1:ncol(sampletable()), function(i) {
plotname <- paste("plot", i, sep="")
plotOutput(plotname, height = 280, width = 250)
})
# Convert the list to a tagList - this is necessary for the list of items
# to display properly.
do.call(tagList, plot_output_list)
})
# Call renderPlot for each one. Plots are only actually generated when they
# are visible on the web page.
for (i in 1:max_plots) {
# Need local so that each item gets its own number. Without it, the value
# of i in the renderPlot() will be the same across all instances, because
# of when the expression is evaluated.
local({
my_i <- i
plotname <- paste("plot", my_i, sep="")
output[[plotname]] <- renderPlot({
plot(sampletable()[,my_i], sampletable()[,my_i],
xlim = c(min(sampletable()[,my_i]), max(sampletable()[,my_i])),
ylim = c(min(sampletable()[,my_i]), max(sampletable()[,my_i])),
main = "look at all those things" )
})
})
}
})
ui.r
library(shinyIncubator)
shinyUI(pageWithSidebar(
headerPanel("Dynamic number of plots"),
sidebarPanel(
sliderInput("n", "this isn't used, I used the ncol function instead, but feel free to move the slider for fun.", value=1, min=1, max=5),
actionButton("go", "Update")
),
mainPanel(
# This is the dynamic UI for the plots
uiOutput("plots")
)
))
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/ff5553de-4a36-414e-a6b7-c77b489cd1f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-...@googlegroups.com.