0

I am trying to generate multiple gvis charts without having to list a large number of $outputs in the server.R file.

server.R

max_plots <- 30

output$plots <- renderUI({
plot_output_list <- lapply(1:input$n, function(i) {
    plotname <- paste("plot", i, sep="")
    plotOutput(plotname, height = 400, width = 7000)
})

do.call(tagList, plot_output_list)

})

for (i in 1:max_plots) {
# Need local so that each item gets its own number. Without it, the value
# of i in the renderPlot() will be the same across all instances, because
# of when the expression is evaluated.
local({
    my_i <- i
    plotname <- paste("plot", my_i, sep="")

    output[[plotname]] <- renderGvis({

        t <- as.data.frame(getClusters[5])

        t <- as.data.frame(t[i,])

        t <- getSnapFrame(t)

        gvisColumnChart(t, xvar = "Feature", yvar = "KPIs", options=list(width=600, height=270, backgroundColor='transparent',  hAxis.gridlines.color="green", colors="['yellowgreen']", fontSize=10, hAxis="{title:'Features', titleTextStyle:{color:'white'}, textStyle:{color: 'white'}}", vAxis="{title:'Relation to Average', titleTextStyle:{color:'white', fontSize: 16}, textStyle:{color: 'white'}}", tooltip="{textStyle: {color: '#0276FD', fontSize: 16}}", legend.position="none"))
    })
})

}

ui.R

sidebarPanel(
sliderInput("n", "Number of plots", value=1, min=1, max=5)
),

uiOutput("plots"), # This is the dynamic UI for the plots
Cybernetic
  • 12,628
  • 16
  • 93
  • 132
  • You can assign to `output` using `[[`. For example `output[[paste0('ColumnCharts, i)]]` – jdharrison Apr 29 '14 at 01:57
  • I get the error: target of assignment expands to non-language object. I also try removing the double quote but the "ColumnCharts1" is not seen as a name for the output. – Cybernetic Apr 29 '14 at 16:03
  • With the double brackets I get "unexpected '[['" – Cybernetic Apr 29 '14 at 16:17
  • Please provide a minimal reproducible example. `runApp` based would be easiest otherwise it is very time consuming to help you. – jdharrison Apr 29 '14 at 16:22
  • I added the code to the question. The other issue is that since the for statement is outside the output, I cannot use an input to set the number of loops. – Cybernetic Apr 29 '14 at 16:29
  • You will need to use `local` see http://stackoverflow.com/questions/15875786/dynamically-add-plots-to-web-page-using-shiny – jdharrison Apr 29 '14 at 16:34
  • I think the problem might be with plotOutput. Is there a version of this for gVis? – Cybernetic Apr 30 '14 at 16:15

0 Answers0