rCharts doesn't render the plot in shiny app

586 views Asked by At

I am using following simple shiny app code snippet to plot the output in the main pannel. But it doesn't render the plot as expected. It shows nothing in the browser. But When i run only the mPlot portion, it displays the plot in RStudio correctly with all interactions.

ui.R
library(shiny)
library(rCharts)

ui<-fluidPage(
  headerPanel("Economics data with rCharts"),
  mainPanel(
    showOutput("myChart","polycharts")
  )
)

server.R
library(shiny)
library(rCharts)
require(datasets)

server<-function(input,output){
  output$myChart<-renderChart({
    data(economics, package = 'ggplot2')
    econ <- transform(economics, date = as.character(date))
    m1 <- mPlot(x = 'date', y = c('psavert', 'uempmed'), type = 'Line',
                data = econ)
    m1$set(pointSize = 0, lineWidth = 1)
    return(m1)
  })

}

1

There are 1 answers

0
Victorp On BEST ANSWER

Hi you use the wrong JS library, it's morris, not polycharts, try :

# ui.R
library(shiny)
library(rCharts)

ui<-fluidPage(
  headerPanel("Economics data with rCharts"),
  mainPanel(
    showOutput("myChart","morris")
  )
)

# server.R
library(shiny)
library(rCharts)
require(datasets)

server<-function(input,output){
  output$myChart<-renderChart2({
    data(economics, package = 'ggplot2')
    econ <- transform(economics, date = as.character(date))
    m1 <- mPlot(x = 'date', y = c('psavert', 'uempmed'), type = 'Line',
                data = econ)
    m1$set(pointSize = 0, lineWidth = 1)
    return(m1)
  })

}

shinyApp(ui = ui, server = server)