echarts4rBox function does not seem to recognize the "x" variable

32 Views Asked by At

I tried this:

library(shiny)
library(echarts4r)

ui <- fluidPage(
  
  fluidRow(
    column(3, echarts4rBoxOutput("box1"))
  )
  
)

server <- function(input, output, session) {
  
  output$box1 <- renderEcharts4rBox({
    echarts4rBox(cars, speed, dist, "Cake", type = "bar")
  })
  
}

shinyApp(ui, server) 

But:

Error: object 'speed' not found

I'm using the latest version of echarts4r, but not working.

1

There are 1 best solutions below

0
polkas On BEST ANSWER

Working code by providing a string x and y columns to the echarts4rBox function call:

library(shiny)
library(echarts4r)

ui <- fluidPage(
    
    fluidRow(
        column(3, echarts4rBoxOutput("box1"))
    )
    
)

server <- function(input, output, session) {
    
    output$box1 <- renderEcharts4rBox({
        echarts4rBox(cars, "speed", "dist", "Cake", type = "bar")
    })
    
}

shinyApp(ui, server) 

The problem comes from invalid transfer and conversion of inputs to the internal .build_data2 function. The echarts4rBox function was designed to accept strings or quotes for x and y inputs, but it does not work with quotes.

> echarts4rBox
function(
  data,
  x,
  y,
  text = "",
  subtext = "",
  type = c("bar", "line", "scatter", "area", "step"),
  ...,
  color = "#ffffff",
  text_color = "#ffffff",
  background_color = "#293c55",
  step = c("start", "middle", "end"),
  title_args = list(),
  tooltip = list(trigger = "axis")
) {

  # for area, keep to use in series opts
  original_type <- type

  # inputs
  type <- match.arg(type)
  step <- match.arg(step)

  # override area
  if (type %in% c("area", "step")) type <- "line"

  # build expected data format
  data <- .build_data2(data, {{ x }}, {{ y }})
  ...