Search code examples
rshinyrchartsrstudio-server

rChart opens new window in shiny application


I am trying to plot a rChart in a shiny application and run this via Rstudio server. When I run the app the shiny page gives the error: attempt to apply non-function and the RChart opens in a new browser window.

How can make the rChart appear in the shiny application?

server.R

library(shiny)
require(rCharts)

names(iris) = gsub("\\.", "", names(iris))

shinyServer(function(input, output) {

output$myChart  <- renderChart({
h1 <- hPlot(x = "Wr.Hnd", y = "NW.Hnd", data = MASS::survey, 
type = c("line", "bubble", "scatter"), group = "Clap", size = "Age")
return(h1$show(cdn = TRUE))
  })
})

ui.R

library(shiny)
require(rCharts)
shinyUI(pageWithSidebar(

headerPanel("rCharts and shiny"),

sidebarPanel(),

mainPanel(
showOutput("myChart")
  )
))

My R session info

R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

other attached packages:
[1] shiny_0.7.0     plyr_1.8        rCharts_0.3.51  devtools_1.3    ggplot2_0.9.3.1    RMySQL_0.9-3    DBI_0.2-7      

Solution

  • You are missing the name of the library in showOutput. If you install the dev branch of rCharts, then you can run the following code

    library(shiny)
    # devtools::install_github("rCharts", "ramnathv", ref = "dev")
    library(rCharts)
    runApp(list(
      ui = pageWithSidebar(
        headerPanel("rCharts and shiny"),
        sidebarPanel(
    
        ),
        mainPanel(
          showOutput("myChart", "highcharts")
      )),
      server = function(input, output, session){
        output$myChart  <- renderChart2({
          h1 <- hPlot(x = "Wr.Hnd", y = "NW.Hnd", data = MASS::survey, 
            type = c("line", "bubble", "scatter"), group = "Clap", 
            size = "Age"
          )
          return(h1)
        })
      }
    ))