无法在R中创建具有动态名称的非反应性RenderPlot对象

无法在R中创建具有动态名称的非反应性RenderPlot对象,r,plot,dynamic,shiny,render,R,Plot,Dynamic,Shiny,Render,我想创建一个动态创建的plotOutput对象 我创建了动态对象来渲染不同的绘图,它们传递了不同的“数据”,因此绘图会有所不同 然后,renderPlot函数被保存在Graph1、Graph2、Graph3中,依此类推我创建了多少次。然后UI元素“w”具有图形1、图形2等的plotOutput 但是当我调用“w”时,最新的图形在w的所有对象中呈现和覆盖 还有其他方法吗? output[[paste0("Graph",i)]]<-{ renderPlot({ggplot2(Data,aes(

我想创建一个动态创建的
plotOutput对象

我创建了动态对象来渲染不同的绘图,它们传递了不同的“数据”,因此绘图会有所不同

然后,
renderPlot
函数被保存在Graph1、Graph2、Graph3中,依此类推我创建了多少次。然后UI元素“w”具有图形1、图形2等的plotOutput

但是当我调用“w”时,最新的图形在w的所有对象中呈现和覆盖

还有其他方法吗?

output[[paste0("Graph",i)]]<-{ renderPlot({ggplot2(Data,aes(x=xxval,y=yval)+geom_point() } 
w<-plotOutput(paste0("Graph",i),height=200,width=300)

output[[paste0(“Graph”,i)]]您希望为此使用函数
insertUI
。我感谢您——我终于找到了一个用例,您必须将输出放在观察者中。下面是一个工作示例

library(ggplot2)

shinyApp(
  ui = fluidPage(
    column(
      width = 3,
      actionButton(
        inputId = "newGraph",
        label = "add Graph"
      ),
      selectInput(
        inputId = "xAxis",
        label = "x-axis",
        choices = colnames(mtcars)
      ),
      selectInput(
        inputId = "yAxis",
        label = "y-axis",
        choices = colnames(mtcars)
      )
    ),
    column(
      width = 9,
      id = "graph_wrapper"
    )
  ),
  server = function(input, output,session) {
  observeEvent(input$newGraph,{
    insertUI(
      selector = '#graph_wrapper',
      where = "beforeEnd",
      ui = plotOutput(
        outputId = paste0("plot",input$newGraph)
      ))
    xxval = input$xAxis
    yval = input$yAxis
    output[[paste0("plot",input$newGraph)]] = renderPlot({
      ggplot(mtcars,aes_string(x=xxval,y=yval))+geom_point() 
    })
  })  
  })
)

希望这有帮助

天哪,这太棒了!!!!感谢您的快速响应和工作示例。这意味着lot@VedhaViyash嗨,Vedya,请考虑一下它是否解决了你的问题。