R Markdown Shiny renderPlot list of plots from lapply

雨燕双飞 提交于 2019-12-04 19:41:26

[New answer]

I finally got this worked out. The key is to exactly follow the example in the third link of your post, using renderUI first!

```{r plot,echo=FALSE,message=FALSE}
tp_list <- reactive({
  i<-names(d())[-1]
  tp<-function(x){
    p<-timePlot(d(),
         pollutant=print(x),
         main="Minute Validation",
         ylab="Minute Conc. (ug/m3 or ppb)",
         key=T)
    p$plot
  }
  lapply(i, tp)
}) 

renderUI({
    plot_output_list <- lapply(1:length(tp_list()), function(i) {
        plotname <- paste("plot", i, sep="")
        plotOutput(plotname)
    })
    do.call(tagList, plot_output_list)
})

observe({
for (i in 1:length(tp_list())) {
    local({
        my_i <- i
        plotname <- paste("plot", my_i, sep="")
        output[[plotname]] <- renderPlot({
            tp_list()[[my_i]]
        })
    })
}
})
```

[Original answer based on lattice panels]

This is not exactly what you want, but I got all the plots displayed in one plot.

```{r plot,echo=FALSE,message=FALSE}
renderPlot({
  i<-names(d())[-1]
  tp<-function(x){
    p<-timePlot(d(),
         pollutant=print(x),
         main="Minute Validation",
         ylab="Minute Conc. (ug/m3 or ppb)",
         key=T)
    p$plot
  }
  tp(i)
}) 
``` 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!