无法在 R 中创建具有动态名称的非反应性 RenderPlot 对象
Unable to create a non reactive RenderPlot object with dynamic names in R
我想创建一个plotOutput object
,动态创建的
我创建了动态对象来渲染不同的情节,它们有不同的 "Data" 通过,所以情节会有所不同。
然后 renderPlot
函数保存在 Graph1、Graph2、Graph3 中,依此类推 i 创建了多少次。然后UI元素"w"有Graph1、Graph2等的plotOutput。
但是当我调用"w"最新的Graph被渲染并覆盖在w的所有对象中。
还有其他方法吗?
output[[paste0("Graph",i)]]<-{ renderPlot({ggplot2(Data,aes(x=xxval,y=yval)+geom_point() }
w<-plotOutput(paste0("Graph",i),height=200,width=300)
你想为此使用函数 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()
})
})
})
)
希望对您有所帮助!
我想创建一个plotOutput object
,动态创建的
我创建了动态对象来渲染不同的情节,它们有不同的 "Data" 通过,所以情节会有所不同。
然后 renderPlot
函数保存在 Graph1、Graph2、Graph3 中,依此类推 i 创建了多少次。然后UI元素"w"有Graph1、Graph2等的plotOutput。
但是当我调用"w"最新的Graph被渲染并覆盖在w的所有对象中。
还有其他方法吗?
output[[paste0("Graph",i)]]<-{ renderPlot({ggplot2(Data,aes(x=xxval,y=yval)+geom_point() }
w<-plotOutput(paste0("Graph",i),height=200,width=300)
你想为此使用函数 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()
})
})
})
)
希望对您有所帮助!