Skip to content

Instantly share code, notes, and snippets.

@reinholdsson
Created March 5, 2014 17:47
Show Gist options
  • Select an option

  • Save reinholdsson/9372477 to your computer and use it in GitHub Desktop.

Select an option

Save reinholdsson/9372477 to your computer and use it in GitHub Desktop.
rCharts - example of Highcharts click events in Shiny
library(shiny)
library(rCharts)
shinyServer(function(input, output) {
output$text <- renderText({
sprintf("The capital of %s is %s.", input$click$country, input$click$capital)
})
output$chart <- renderChart({
a <- Highcharts$new()
a$series(data = list(
list(x = 0, y = 40, capital = "Stockholm", country = "Sweden"),
list(x = 1, y = 50, capital = "Copenhagen", country = "Denmark"),
list(x = 2, y = 60, capital = "Oslo", country = "Norway")
), type = "bar"
)
a$xAxis(categories = c("Sweden", "Denmark", "Norway"))
a$plotOptions(
bar = list(
cursor = "pointer",
point = list(
events = list(
click = "#! function() {
Shiny.onInputChange('click', {
capital: this.capital,
country: this.country
})
} !#"))
)
)
a$addParams(dom = "chart")
return(a)
})
})
library(shiny)
library(rCharts)
shinyUI(bootstrapPage(
chartOutput("chart", "highcharts"),
textOutput("text")
))
@adrienbruno
Copy link
Copy Markdown

work fine removing the "highcharts" in chartOutput. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment