dreamRs / apexcharter

:bar_chart: R Htmlwidget for ApexCharts.js
https://dreamrs.github.io/apexcharter
Other
138 stars 15 forks source link

Auto update not working in Shiny #46

Closed tobiasblasberg closed 2 years ago

tobiasblasberg commented 3 years ago

Hi,

updating the color of a plot in shiny is not working, similar to other configuration like the stroke width.

It took me quite some time to figure out what causes this issue: Although auto_update is set to TRUE as default in the apexchart function, the parameter fig$x$auto_update$update_options is FALSE after creating the plot.

This causes that updating the color palette based on some shiny input variable (i.e. number of series) is not applied although the data update is performed correctly within shiny. I am doing that to apply a specific color to a specific data series if selected from an input.

The following code structure leads to the issue:

output$kpi_area_chart <- apexcharter::renderApexchart({
... some logical modifying the color pallete...

fig <- apexcharter::apexchart(ax_opts = list(
... chart config...
 colors = my_chaged_color_palette,
))
})
fig

When changing the paramater the color palette will not change although the parameter has changed.

For now, a solution is adding

fig$x$auto_update$update_options <- TRUE
pvictor commented 3 years ago

Yes, this is a little confusing, sorry. To update options and data you can use:

apex(..., auto_update = config_update(update_options = TRUE))

Or auto_update = FALSE and the chart will be destroyed and redraw.

Victor