I have multiple highcharts in my shiny app and the structure is similar in all of them, so I'm trying to use a function to generalise:
- In my data file:
Edit
set.seed(5) data <- data.frame(id=1:10, period=seq(2011,2020, 1), program=rep(LETTERS[1:2], 5), total=rnorm(10))
gral <- function(df,x,y,group,theme){
highchart() %>%
hc_xAxis(type = "category") %>%
hc_add_series(df, "line",
hcaes(x = x, y = y
,group = group),
dataLabels = list(enabled = TRUE,
style = list(fontSize = '13px'))
) %>%
hc_legend(enabled = TRUE) %>%
hc_tooltip(shared = TRUE, crosshairs = TRUE
,style = list(fontSize = "18px")
) %>%
hc_add_theme(theme) }
- In my server file (for each highchart)
output$usuariosgral <- renderHighchart({ gral(df = data, x = period, y = total, group = program, theme = hc_theme_elementary()) })
But it is not working, anyone knows why?
Finally, I found the answer here, in case it is useful to anyone --> https://stackoverflow.com/a/64392483/13529820
Just need to use the function ensym
from library rlang
. So in my code jus changed the hcaes
line to this:
hcaes(x = !!rlang::ensym(x), y = !!rlang::ensym(y), group = !!rlang::ensym(group))