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

Get data from shiny with the following:

  • elementId + _brush
  • elementId + _legend_change
  • elementId + _clicked_data
  • elementId + _clicked_data_value
  • elementId + _clicked_row
  • elementId + _clicked_serie
  • elementId + _mouseover_data
  • elementId + _mouseover_data_value
  • elementId + _mouseover_row
  • elementId + _mouseover_serie

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)

You can also show a spinner while shiny recalculates.

Without loading, chart redraws with neat animation.

# no redraw
# no loading
library(shiny)
ui <- fluidPage(
  fluidRow(
    column(12, actionButton("update", "Update"))
  ),
  fluidRow(
    column(12, echarts4rOutput("plot"))
  )
)

server <- function(input, output){
  data <- eventReactive(input$update, {
    data.frame(
      x = 1:10,
      y = rnorm(10)
    )
  })
  
  output$plot <- renderEcharts4r({
    data() %>% 
      e_charts(x) %>% 
      e_bar(y)
  })
}

shinyApp(ui, server)

With loading.

# keep UI
# add loading
server <- function(input, output){
  data <- eventReactive(input$update, {
    Sys.sleep(1) # sleep one second to show loading
    data.frame(
      x = 1:10,
      y = rnorm(10)
    )
  })
  
  output$plot <- renderEcharts4r({
    data() %>% 
      e_charts(x) %>% 
      e_bar(y) %>% 
      e_show_loading()
  })
}

shinyApp(ui, server)