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

Dynamically update axes when changing the chart type via proxies #573

Open
j-kreis opened this issue Sep 20, 2023 · 3 comments
Open

Dynamically update axes when changing the chart type via proxies #573

j-kreis opened this issue Sep 20, 2023 · 3 comments

Comments

@j-kreis
Copy link

j-kreis commented Sep 20, 2023

I would like to transition between chart types dynamically (#440). Could you please provide details on how to use e_morph within a shiny app using a proxy?

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({
    echarts4r::e_charts(data) |>
    echarts4r::e_axis_labels(x = "", y = "")
  })

  observeEvent(input$switch, {

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

    active_class = class(data[[col]])

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

    if (active_class =="numeric") {
      echarts4rProxy(id = "plot", session = session,
                     data = data)|>
        e_density(num) |>
        e_execute()
    } else {
      data |>
        dplyr::ungroup() |>
        dplyr::count(!!rlang::sym(col)) |>
        echarts4rProxy(id = "plot", session = session) |>
        echarts4r::e_bar(n, legend = FALSE) |>
        e_execute()
    }

    column(col)
  })
}

shinyApp(ui, server)

@munoztd0
Copy link
Collaborator

munoztd0 commented Oct 2, 2023

Not really sure what do you want, maybe screenshots of what you expect would help ? related to #570 ?

@j-kreis
Copy link
Author

j-kreis commented Oct 10, 2023

I wanted to generically switch between plot types. Similar to this example. Switching between bar, scatter, pie and other plots, using the same or different data.

@JohnCoene
Copy link
Owner

Then look at what @munoztd0 shared, you want e_morph, see docs let us know if you have questions on how to implement it

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

3 participants