Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with echarts4rProxy #572

Open
j-kreis opened this issue Sep 20, 2023 · 1 comment
Open

Issues with echarts4rProxy #572

j-kreis opened this issue Sep 20, 2023 · 1 comment

Comments

@j-kreis
Copy link

j-kreis commented Sep 20, 2023

Related to #300, #276, #291, #209 . Working with v0.4.5 I am not able to update the series using e_bar, e_density_, or other functions like e_tooltip or e_title. However, it is supposed to work like implemented below?

library(echarts4r)
library(shiny)

ui <- fluidPage(
  actionButton("switch", "Switch data"),
  echarts4rOutput("plot")
)

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

  data = tibble::tibble(chr = sample(letters[1:5], size = 100, replace = TRUE),
                        num = rnorm(100))

  column = reactiveVal("chr")

  output$plot <- renderEcharts4r({
    data |>
      dplyr::ungroup() |>
      dplyr::count(chr) |>
      echarts4r::e_charts(chr) |>
      echarts4r::e_title("Foo", "Bar") |>
      echarts4r::e_bar(n, legend = FALSE)
  })

  observeEvent(input$switch, {

    col = setdiff(colnames(data), column())

    # Update plot depending on the class of the column
    update_p(data, column = col, id="plot", session=session)

    # update current column
    column(col)
  })
}

update_p = function(x, column, title=NULL, x_title=NULL, id=NULL,
                    session=NULL) {

  active_class = class(x[[column]])


  echarts4rProxy(id = "plot", session = session) |>
    echarts4r::e_remove_serie_p(serie_index = 1)

  if (active_class == "numeric") {
    echarts4rProxy(id = "plot", session = session,
                   data = x)|>
      echarts4r::e_density(num) |>
      # echarts4r::e_axis_labels(x = "Foo") |> # Warning: Error in !: invalid argument type
      # echarts4r::e_tooltip(trigger = "axis") |> # Warning: Error in !: invalid argument type
      # echarts4r::e_density_(column) |> # Does not update the app
      # echarts4r::e_title("Bar", "Foo") |> # Warning: Error in !: invalid argument type
      echarts4r::e_execute_p()
  } else {
    x = x |>
      dplyr::ungroup() |>
      dplyr::count(!!rlang::sym(column)) |>
      echarts4rProxy(id = "plot", session = session) |>
      echarts4r::e_bar(n, legend = FALSE) |> # Does not update the app
      echarts4r::e_execute_p()
  }
}


shinyApp(ui, server)

@munoztd0
Copy link
Collaborator

munoztd0 commented Oct 2, 2023

related to #570 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants