Recently, I encountered an issue with a htmlwidget in one of my R shiny applications. Each time the widget render function was called multiple times, it failed to replace the existing data with new data. This bug caused the old data to linger and the new data to be appended on top of it.
To demonstrate this problem, I created a reproducible example. By clicking on the 'ui2' button, the application transitions to another ui. Then, upon clicking the 'reset' button from that ui, it returns to the default ui where you can observe two histograms within the same container instead of just one. This anomaly occurs because I am struggling to replace the old data with new data in my htmlwidget.
Reproducible Shiny App:
#library(devtools)
#install_github('radhikesh/d3Viz')
library(shiny)
library(d3Viz)
# Rest of the server code...
d3Histogram.js code
// JavaScript code for the d3Histogram widget goes here
//....
I believe the root cause lies in replacing the old data with new data in the JavaScript binding, but my knowledge of JavaScript is limited, making it challenging to address this issue. Any assistance or guidance would be greatly appreciated.
Thank you,
Radhikesh