4

I'm attempting to add a variable number of plots to a page.

With each page I add, I'd also like to add some control boxes. Adding all of this to the page isn't the problem, the problem arises when i attempt to use the input boxes to control the plots. the input values aren't recognized inside the plot definitions.

How can I make this work?

runApp(list(
ui = shinyUI(
  bootstrapPage(
    numericInput('n.plots', "Number of Plots", 2),
    uiOutput('plots')
  )
),
server = shinyServer(function(input, output, session){
  for(i in 1:max.plots){
    local({
      my.i <- i
      plotname <- paste('plot',my.i, sep = '')
      output[[plotname]] <- renderPlot({
# Work in plot (not reactive though)
#         hist(rnorm(100, input[[paste('mean_', my.i)]], input[[paste('sd_', my.i)]]))
# Doesn't work
        hist(rnorm(100, input[[paste('mean_', my.i)]], input[[paste('sd_', my.i)]]))
      })
    })
  }

  output$plots <- renderUI({
    out <- ''
    for(i in 1:input$n.plots){
      additional <- fluidRow(

        column(width = 4,
               wellPanel(
                 h5(paste('Thing', i)),
                 numericInput(paste('mean_',i, sep = ''), 'Mean', 100),
                 numericInput(paste('sd_', i, sep = ''), 'SD', 25)
               )
        ),
        column(width = 8,
               plotOutput(paste('plot',i, sep = ''))
        )
      )
      out <- paste(out, additional)
    }
    HTML(out)
  })
})
)
)
Sam Helmich
  • 949
  • 1
  • 8
  • 18
  • 1
    Define `max.plots` and you probably want to change `paste('mean_', my.i)` and `paste('sd_', my.i)` to include `sep=""`. If that fixes your issues then I'll post it as a solution. – Dason Jun 30 '14 at 19:29
  • Possible repeat of Possible repeat of http://stackoverflow.com/questions/15875786/dynamically-add-plots-to-web-page-using-shiny – Nick Jul 01 '14 at 01:46

0 Answers0