echarts4r
echarts4r copied to clipboard
Issues with echarts4rProxy
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)
related to #570 ?