JohnCoene / echarts4r

🐳 ECharts 5 for R
http://echarts4r.john-coene.com/
Other
585 stars 82 forks source link

'Cannot find function renderEcharts4r' error in Shiny Quarto document #609

Closed jennyv0 closed 6 months ago

jennyv0 commented 6 months ago

I am creating a quarto/shiny doc that has an echart graphic in it with a simple radio button input widget, but the document isn't rendering with an error that says 'Error in renderEcharts4r({ : could not find function "renderEcharts4r" '.

Below is a reproducible example. Any ideas on what the issue is?

Thanks

---
title: "Test"
format: html
server: shiny
execute:
  echo: false
  warning: false
---

```{r}

#| label: setup

library(dplyr)
library(echarts4r)
library(shinyWidgets)
library(lubridate)

data("USAccDeaths")
USAccDeaths <- data.frame(as.matrix(USAccDeaths), date=time(USAccDeaths))
USAccDeaths$year <- trunc(USAccDeaths$date)
USAccDeaths$month <- (USAccDeaths$date - USAccDeaths$year) * 12 + 1
colnames(USAccDeaths)[1] <- 'Deaths'

radioGroupButtons(
  inputId = "time_period",
  label = "Choices", 
  choices = c("Month", "Year"),
  status = "primary"
)

echarts4rOutput("plot1")

#| context: server

deaths <- reactive({
  USAccDeaths %>% 
    group_by(tolower(input$time_period)) %>% 
    summarise('Deaths' = sum(deaths))
})

output$plot1 <- renderEcharts4r({
  deaths |> 
    e_charts(x = tolower(input$time_period)) |> # initialise and set x
    e_line(serie = Deaths, smooth = TRUE) |>
    e_tooltip(trigger = "axis")

})
jennyv0 commented 6 months ago

AHA!

There were a few things I needed to change, including: