Skip to content

e_append1_p() has a bug and doesn't append but replace data #670

@g-no

Description

@g-no

Thanks a lot for this wonderful package!

In append.R function e_append1_p()

e_append1_p_ <- function(proxy, series_index = NULL, data, x, y, name = NULL) {
  ...
  dlist <- data |>
    dplyr::select(x, y,name) |>
  ...

the name in e_append1_p is not in the right place, I think, because it assumes that the input data always has a column called name, regardless of whether the argument name is NULL. Therefore, when dplyr::select() tries to select name, it throws an error: "Can't subset columns that don't exist."

I get around the problem by adding a column name to the data-to-append like in this code:

library(shiny)
library(echarts4r)

ui <- fluidPage(
  actionButton("append", "Append data pairs"),
  echarts4rOutput("plot")
)

server <- function(input, output, session) {
  # start with one point
  base <- data.frame(x = c(4, 3), y = c(4, 3))

    output$plot <- renderEcharts4r({
    base |>
      e_charts(x,  reorder = FALSE) |>
        e_line(y, name = "path", showSymbol = FALSE) |>
        e_animation(show = FALSE)
    })
  
  new <- data.frame(x = c(2, 1), y = c(2, 1), name = "bug")
  
  observeEvent(input$append, {
    echarts4rProxy("plot") |>
      e_append1_p(series_index = 0, data = new, x = "x", y = "y", name = "path") 
  })
}

shinyApp(ui, server)

However, the new data is not appended, but replaces the previous data.

BTW: the argument reorder = FALSE is missing in the help files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions