Search code examples
rshinynvd3.jsrcharts

Shiny and rCharts: I don't get it to work


I somehow don't get it to work. Nothing is displayed, but no error is shown. This is from my UI, so all libraries are loaded:

tags$head(
                        tags$link(rel = "stylesheet", type = "text/css", href = "style_mozilla_win.css"),
                        tags$link(rel = "stylesheet", type = "text/css", href="nv.d3.css")
                      ),

                      HTML('
                           <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
                           '),

....

mainPanel( 
                                              showOutput("SectorCharting", "nvd3")
                                            )

And from my server.R

output$SectorCharting<-renderChart({
      hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male")
      n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, 
                  type = 'multiBarChart')

      return(n1)
  })

Solution

  • This is the same problem as here yesterday here and many before that, use Use renderChart2 instead of renderChart.

    rm(list = ls())
    library(shiny)
    library(rCharts)
    
    ui =pageWithSidebar(
      headerPanel("Test"),
    
      sidebarPanel(),
      mainPanel(
        showOutput("SectorCharting", "nvd3")
      )
    )
    
    
    server = function(input, output) {
    
      output$SectorCharting <-renderChart2({
        hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male")
        n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, 
                    type = 'multiBarChart')
        return(n1)
      })
    }
    
    
    runApp(list(ui = ui, server = server))