refreshing highcharts in shiny

673 views
Skip to first unread message

Joseph Lee

unread,
Mar 26, 2014, 3:46:01 PM3/26/14
to shiny-...@googlegroups.com
In base rcharts highcharts, you can toggle a series in the legend and the graph will redraw itself with/without the toggled series.  However, in shiny the graph doesn't redraw itself when toggling the series.  Instead, the colors go away, but the underlying layers remain in place with the wrong colors .  Any idea how to force the refresh?

Also, when exporting is enabled, saving as a file breaks the server connection and the screen grays out.  Any ideas how to prevent this?

Joseph Lee

unread,
Mar 26, 2014, 3:53:00 PM3/26/14
to shiny-...@googlegroups.com
I should clarify that I'm creating a stacked bar chart.

Joseph Lee

unread,
Mar 29, 2014, 6:59:31 PM3/29/14
to shiny-...@googlegroups.com
Here's some example code.  In shiny, when clicking on Joe, the plot won't redraw itself.  However, clicking on all 4 values in the legend and then adding one back will force it to redraw.  I'm running rCharts 0.4.2 and shiny 0.9.1.

If you drop out of shiny and then plot local_a, then you can click on Joe in the viewer and the plot redraws itself nicely.

Anyone else experienced this behavior?

## ui.R
require(shiny)
require(rCharts)
shinyUI(pageWithSidebar(
  headerPanel("rCharts"),
  sidebarPanel(
  ),
  mainPanel(
    chartOutput("myChart", "highcharts")
  )
))

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

shinyServer(function(input, output) {
  output$myChart <- renderChart2({
    
    df <- data.frame(
      name = c("John", "John", "Joe", "Joe", "Jane", "Jane", "Janet", "Janet"),
      data = sample(1:10, 8, replace = T),
      stack = c(rep("male", 4), rep("female", 4))
    )
    
    a <- rCharts:::Highcharts$new()
    
    a$chart(type = "column")
    a$plotOptions(column = list(stacking = "normal"))
    a$xAxis(categories = c("Apples", "Oranges"))
    
    # a$series(name = "John", data = c(5, 3), stack = "male")
    # a$series(name = "Joe", data = c(3, 4), stack = "male")
    # a$series(name = "Jane", data = c(2, 5), stack = "female")
    # a$series(name = "Janet", data = c(3, 1), stack = "female")
    
    invisible(sapply(unique(df$name), function(name){
      d <- df[df$name == name, ]
      a$series(name = name, data = d$data, stack = d$stack[[1]])
    }))
    
    local_a <<- a
    return(a)
  })
})

On Wednesday, March 26, 2014 12:46:01 PM UTC-7, Joseph Lee wrote:

Joseph Lee

unread,
Mar 29, 2014, 7:45:44 PM3/29/14
to shiny-...@googlegroups.com
Looks like it's a manifestation of this bug:


Not a shiny issue, it's a highcharts jquery issue.  If I run it in R, then it will load the jQuery included with highcharts with rCharts, which is 1.9.1.  If I run it as an app, it loads jQuery 1.11.0, which is where the problem comes from.


On Wednesday, March 26, 2014 12:46:01 PM UTC-7, Joseph Lee wrote:

Connie Zabarovskaya

unread,
Aug 19, 2014, 10:31:29 AM8/19/14
to shiny-...@googlegroups.com
Hi Joseph,

I'm tackling the same issue. I really wish to use highcharts stacked column and bar charts, but this bug is ruining the experience.

Did you ever figure out a solution for rCharts Highcharts? It seems in that stackoverflow thread they fixed the issue in Highcharts itself.

Thanks!
Reply all
Reply to author
Forward
0 new messages