echarts4r comes with proxies (functions ending in _p) as well as the ability access selected data. You will find a demo of shiny working with echarts4r here.

Shiny Demo

Callbacks

Get data from shiny with the following:

  • elementId + _brush - returns data on brushed data points.
  • elementId + _legend_change - returns series name of legend selected/unselected.
  • elementId + _clicked_data - returns data of clicked data point.
  • elementId + _clicked_data_value - returns value of clicked data point.
  • elementId + _clicked_row - returns row number of clicked data point.
  • elementId + _clicked_serie - returns name of serie of clicked data point.
  • elementId + _mouseover_data - returns data on hovered data point.
  • elementId + _mouseover_data_value - returns value of hovered data point.
  • elementId + _mouseover_row - returns row o hovered data point.
  • elementId + _mouseover_serie - returns name of serie of hovered data point.

If you want to implement a missing callback with e_distpatch_action_p.

Proxies

Interact with the charts without redrawing (proxies):

  • e_append1_p and e_append2_p - to add data to your chart.
  • e_highlight_p and e_downplay_p - to highlight or downplay a serie.
  • e_showtip_p and e_hidetip_p - to Show or hide the tooltip.
  • e_draw_p to draw the chart, see function documentation for examples.
  • e_focus_adjacency and e_unfocus_adjacency - to focus or unfocus on adjacent nodes (networks).

See the example below and the various proxies documentation.

library(shiny)
library(echarts4r)

ui <- fluidPage(
  actionButton("add", "Add Data to y"),
  echarts4rOutput("plot"),
  verbatimTextOutput("selected")
)

server <- function(input, output, session){

  data <- data.frame(x = rnorm(10, 5, 3), y = rnorm(10, 50, 12), z = rnorm(10, 50, 5))
  
  react <- eventReactive(input$add, {
    set.seed(sample(1:1000, 1))
    data.frame(x = rnorm(10, 5, 2), y = rnorm(10, 50, 10))
  })
  
  output$plot <- renderEcharts4r({
    data %>% 
     e_charts(x) %>% 
     e_scatter(y) %>%
     e_scatter(z) %>% 
     e_brush(throttleDelay = 1000)
  })
  
  observeEvent(input$add, {
    echarts4rProxy("plot") %>% 
      e_append1_p(0, react(), x, y)
  })
  
  output$selected <- renderPrint({
    input$plot_brush
  })
  
}

shinyApp(ui, server)

Loading

You can also show a spinner while shiny recalculates.

Without loading, chart redraws with neat animation.

With loading.