0
votes

I am working with a d3pie rChart. It works when I view it in the rStudio viewer. When I try to enter it into a shiny app, I get an error:

Error in addResourcePath(LIB$name, LIB$url) : object 'LIB' not found

It wants me to tell it what library I am working with in showOutput('chart1','LIB') (e.g., Nvd3, Highcharts), but I'm not sure which one to use.

Similarly, when I save the d3pie chart as an html file, it won't open in my browser. Is there a way around this?

Data:

x <- data.frame(table = as.factor(c("A","B","C","D","E","F")), 
     value = c(518,39,337,304,56,7))

Code for d3pie:

require(magrittr)
require(dplyr)
require(rCharts)
rPie <- rCharts$new()
rPie$setLib("http://timelyportfolio.github.io/rChartsExtra/d3pie")
rPie$addParams(
  chartspec = list(
    header = list(
      title = list(
        text = "Breakdown of 2014 Revenue Sources"
      )
    )
    ,data = list(
      content = x
    )
  )
)
rPie

server.R:

require(rCharts)
require(reshape)
require(magrittr)
require(dplyr)

x <- data.frame(table = as.factor(c("A","B","C","D","E","F")), 
                value = c(518,39,337,304,56,7))

shinyServer(function(input, output) {
  output$chart1 <- renderChart2({
    rPie <- rCharts$new()
    rPie$setLib("http://timelyportfolio.github.io/rChartsExtra/d3pie")
    cat(add_lib_assets(rPie$lib,cdn=T))
    rPie$addParams(
      chartspec = list(
        header = list(
          title = list(
            text = "This is the title"
          )
        )
        , data = list(
          content = x
        )
      )
    )
    rPie$set(dom = "chart1")
    return(rPie)
  })
})

ui.R:

require(rCharts)

shinyUI(fluidPage(
  titlePanel("Shiny App"),

  mainPanel(
               showOutput('chart1')
      ) 
    )
  )
1

1 Answers

0
votes

To make it work in shiny, you need to add d3pie as the lib in your showOutput:

showOutput('chart1','d3pie')

You also to download the extra libraries and copy/paste the d3pie folder in the same folder as where your server.R and ui.R are.