Code Monkey home page Code Monkey logo

Comments (2)

JohnCoene avatar JohnCoene commented on June 11, 2024 1

Thanks for the detailed issue once again!

I'm afraid I haven't had any luck either. Doesn't work in pure. JavaScript either, echarts4r proxy code does execute but echarts.js fails to show the tooltip.

Perhaps we'll need to update the JavaScript dependencies in echarts4r.

from echarts4r.

yogat3ch avatar yogat3ch commented on June 11, 2024

After much trial & error, I've managed to get e_highlight_p and e_downplay_p to work in tandem with one another, but no luck on the tooltips:

library(shiny)
devtools::load_all()

ui <- fluidPage(
  fluidRow(
    column(6, echarts4rOutput("plot")),
    column(6, echarts4rOutput("plot2"))
  )
)

server <- function(input, output, session) {
  output$plot <- renderEcharts4r({
    mtcars |>
      e_charts(mpg) |>
      e_line(disp, bind = carb, name = "displacement", emphasis = list(
        disabled = FALSE,
        lineStyle = list(opacity = 1,
                         width = 6)
      )) |>
      e_line(hp, emphasis = list(
        disabled = FALSE,
        lineStyle = list(opacity = 1,
                         width = 6)
      )) |>
      e_x_axis(min = 10) |>
      e_tooltip() |>
      e_theme("westeros") |> 
      e_group('p') |> 
      e_on(
        "series",
        event = "mouseover", 
        "
        (event) => {
          Shiny.setInputValue('plot_mouseover_seriesIndex', event.seriesIndex, {priority: 'event'})
        }
        "
      ) |> 
      e_on(
        "series",
        event = "mouseover", 
        "
        (event) => {
          Shiny.setInputValue('plot_mouseout_seriesIndex', event.seriesIndex, {priority: 'event'})
        }
        "
      )
  })
  output$plot2 <- renderEcharts4r({
    mtcars |>
      e_charts(mpg) |>
      e_line(disp, bind = carb, name = "displacement", emphasis = list(
        disabled = FALSE,
        lineStyle = list(opacity = 1,
                         width = 6)
      )) |>
      e_line(hp, emphasis = list(
        disabled = FALSE,
        lineStyle = list(opacity = 1,
                         width = 6)
      )) |>
      e_x_axis(min = 10) |>
      e_tooltip() |>
      e_theme("westeros") |> 
      e_group('p') |> 
      e_on(
        "series",
        event = "mouseover", 
        "
        (event) => {
          Shiny.setInputValue('plot2_mouseover_seriesIndex', event.seriesIndex, {priority: 'event'})
        }
        "
      ) |> 
      e_on(
        "series",
        event = "mouseout", 
        "
        (event) => {
          Shiny.setInputValue('plot2_mouseout_seriesIndex', event.seriesIndex, {priority: 'event'})
        }
        "
      )
    # |> 
    #   e_connect_group("p")
  })


  browse = FALSE
  observeEvent(input$plot_mouseover_seriesIndex, {
    cli::cli_inform("plot_mouseover")
    if (browse)
      browser()
    prox <- echarts4rProxy("plot2")
    e_dispatch_action_p(
      prox,
      "select",
      seriesIndex = input$plot_mouseover_seriesIndex
    )
    e_showtip_p(
      prox,
      seriesIndex = input$plot_mouseover_seriesIndex
    )
    e_highlight_p(
      prox,
      series_index = input$plot_mouseover_seriesIndex
    )
  })
  observeEvent(input$plot2_mouseover_seriesIndex, {
    cli::cli_inform("plot2_mouseover")
    if (browse)
      browser()
    prox <- echarts4rProxy("plot")
      e_dispatch_action_p(
        prox,
        "select",
        seriesIndex = input$plot2_mouseover_seriesIndex
      )
      e_showtip_p(
        prox,
        seriesIndex = input$plot2_mouseover_seriesIndex
      )
      e_highlight_p(
        prox,
        series_index = input$plot2_mouseover_seriesIndex
      )
  })
  observeEvent(input$plot_mouseout_seriesIndex, {
    cli::cli_inform("plot2_mouseout")
    if (browse)
      browser()
    prox <- echarts4rProxy("plot2")
    e_dispatch_action_p(
      prox,
      "select",
      seriesIndex = input$plot_mouseout_seriesIndex
    )
    e_hidetip_p(
      prox
    )
    e_downplay_p(
      prox,
      series_index = input$plot_mouseout_seriesIndex
    )
  })
  observeEvent(input$plot2_mouseout_seriesIndex, {
    cli::cli_inform("plot2_mouseout")
    if (browse)
      browser()
    prox <- echarts4rProxy("plot")
      e_dispatch_action_p(
        prox,
        "select",
        seriesIndex = input$plot2_mouseout_seriesIndex
      )
      e_hidetip_p(
        prox
      )
      e_downplay_p(
        prox,
        series_index = input$plot2_mouseout_seriesIndex
      )
  })





}

if (interactive()) {
  shinyApp(ui, server)
}

from echarts4r.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.