Dynamic number of reactive sites with Shiny

I am trying to add a variable number of graphs to a page.

With every page I added, I would also like to add some control boxes. Adding all this to the page is not a problem, the problem arises when I try to use input fields to manage graphs. input values ​​are not recognized within the graph definitions.

How can I do this job?

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)
  })
})
)
)
+4
source share

Source: https://habr.com/ru/post/1546609/


All Articles