使用Shiny

时间:2017-10-12 15:36:17

标签: r shiny

是否有一种优雅的方法可以将图形附加到Shiny中的渲染堆栈/数组而不是覆盖现有的图?我希望新页面显示在页面底部,以便用户可以向上滚动以查看其以前的工作。这是一个起点:

require(shiny)

server = function(input, output, session) {
  observeEvent(input$execute, {
    x = sort(rnorm(input$input))
    output$plot = renderPlot( plot(x, type='l') )
  })
}

ui = fluidPage(
  sidebarPanel(width=4,
  numericInput('input', 'Enter positive number and click \'Go\'. Then repeat with other numbers', value = NA, min = 1),
  actionButton('execute', 'Go')
  ),
  mainPanel( plotOutput('plot') )
)

shinyApp(ui, server)

enter image description here

1 个答案:

答案 0 :(得分:3)

会这样吗?

require(shiny)

ui = fluidPage(
  sidebarPanel(width=4,
               numericInput('input', 'Enter positive number and click \'Go\'. Then repeat with other numbers', value = 123, min = 1),
               actionButton('execute', 'Go')
  ),
  mainPanel(tags$div(id="rowLabel",mainPanel()))
)

server = function(input, output, session) {

  observeEvent(input$execute, {
    insertUI(
      selector = "#rowLabel",
      where = "afterEnd",
      ui = column(8,"Example2",plotOutput(paste0("Plot", input$execute)))

    )
  })

  observeEvent(input$execute, {
    plotname <- paste0("Plot", input$execute)
    x = sort(rnorm(input$input))
    output[[plotname]] = renderPlot( plot(x, type='l') )
  })
}

shinyApp(ui, server)

enter image description here