Created
March 5, 2014 17:47
-
-
Save reinholdsson/9372477 to your computer and use it in GitHub Desktop.
rCharts - example of Highcharts click events in Shiny
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(rCharts) | |
shinyUI(bootstrapPage( | |
chartOutput("chart", "highcharts"), | |
textOutput("text") | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
work fine removing the "highcharts" in chartOutput. thanks