daattali daattali - 5 months ago 41
R Question

How to create an empty plot in rCharts?

I'm trying to add an rCharts output to a shiny app. If the inputs are not valid, then I don't want to output anything - so I'd like to be able to just return

or somehow have an "empty plot" in the output. But I can't figure out how to create an empty plot in rCharts.

Here's the code I have, the example is taken straight out of the README but I commented out the plot code and returned NULL instead


ui <- pageWithSidebar(
headerPanel("rCharts: Interactive Charts from R using polychart.js"),

selectInput(inputId = "x",
label = "Choose X",
choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'),
selected = "SepalLength"),
selectInput(inputId = "y",
label = "Choose Y",
choices = c('SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'),
selected = "SepalWidth")
showOutput("myChart", "polycharts")

server<- function(input, output) {
output$myChart <- renderChart({
# names(iris) = gsub("\\.", "", names(iris))
# p1 <- rPlot(input$x, input$y, data = iris, color = "Species",
# facet = "Species", type = 'point')
# p1$addParams(dom = 'myChart')
# return(p1)

shinyApp(ui, server)


showOutput expects an object back right, so why do you give back an empty object of that class.

output$myChart <- renderChart({
        mychart <- Polycharts$new()