library(shiny)
library(rCharts)
runApp(list(
ui = fluidPage(
fluidRow(
splitLayout(
uiOutput("piePlots")
)
)
),
server = function(input, output) {
#' Generate a graphic summary of the dataset, using rCharts
output$piePlots <- renderUI({
data <- data.frame (varX=c("a","a","b"), varY = c("c","d","c"))
plot_output_list <- lapply(names(data), function(i) {
plotname <- paste("plot", i, sep="")
chartOutput(plotname, "highcharts")
})
# Convert the list to a tagList - this is necessary for the list of items
# to display properly.
do.call(tagList, plot_output_list)
})
observe ({
data <- data.frame (varX=c("a","a","b"), varY = c("c","d","c"))
# Call renderChart for each one.
for (i in names(data)) {
# Need local so that each item gets its own name. Without it, the value
# of i in the renderChart2() 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]] <- renderChart2({
plotData <- data.frame(table(data[, my_i]))
hPlot(x = "Var1", y = "Freq", data = plotData, type = "pie", title = my_i)
})
})
}
})
}
))