Comments (2)
This is 6 months late, but it might help someone else with the same question. I think your problem is in your d3 script. For each draw-iteration you add points and lines, and you should also remove unused values from the prior iteration. The d3 update pattern (https://bl.ocks.org/mbostock/3808218) shows a select, then a data join, then a merge, then a remove. In my limited experience r2d3 doesn't make good use of the merge function so I find just the select, join, and remove to be the way to go, and (maybe incorrectly) I just go ahead and remove all elements before drawing new ones for each iteration.
for example, your lines are:
focus.selectAll('lines')
.data(dById)
.enter().append("path")
.attr("class", "line")
.attr("d", function(d) {
return connectLine(d.values);
})
.attr("stroke", function(d) {
return color(d.key);
})
.attr('stroke-width', 4);
To clear all existing lines and draw new ones you could try:
// start with the svg object provided by r2d3
svg.selectAll('lines').remove();
focus.selectAll('lines')
.data(dById)
.enter().append("path")
.attr("class", "line")
.attr("d", function(d) {
return connectLine(d.values);
})
.attr("stroke", function(d) {
return color(d.key);
})
.attr('stroke-width', 4);
You might be able to simplify this even more by removing all g
elements at the top of your d3 script.
from r2d3.
Just found this, which I think is the same issue: https://stackoverflow.com/questions/44348963/replace-existing-r-shiny-htmlwidget-data-with-new-data
The responses there didn't help me much though :/ I suspect that each call to r2d3 creates a new htmlwidget (each of them using the same set of bindings? given that the old instances respond to new input too?) and that what's needed is to delete either just the old widget or the widget plus the bindings from within shiny before making a new call to r2d3 - correct?
from r2d3.
Related Issues (20)
- forcegraph.js using container = "canvas" not working
- Data passed to multiple charts HOT 1
- Render r2d3 output in rmarkdown document with `rmarkdown::knitr()` function
- Request: Add support for version 7 of D3
- r2d3 bubbles example is not rendering output
- Pass info from D3 back to [R] HOT 1
- Error adding multiple dependencies HOT 1
- Debugging: Rstudio D3 Preview with Full R Code HOT 1
- Why does the image produced from r2d3 is static?
- Implementing D3 6.0 HOT 4
- Question: r2d3 still maintained? HOT 2
- Inproper data join after input change HOT 1
- Width and Height parameters don't seem to work
- Quick questions about width and height HOT 1
- Move `master` branch to `main` HOT 1
- D3 preview in RStudio does not render imported SVG
- Cleanup the README formatting
- "publishing.html" documentation article has mis-rendered R code blocks
- Brush selection lost after page resize
- issues when rendering an r2d3-based package's plots in shiny
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from r2d3.