Comments (13)
Progress: Thanks to @AliciaSchep's advice, now renders in RStudio IDE window, but not yet inline in Rmd notebooks.
from altair.
I think I have made some progress in understanding why there is an error with 'inline' notebook display in altair widgets. This is a super weird bug.
Rstudio adds some javascript code into the header of the html for the notebook chunk view:
(See this search of rstudio repo for some clues on how rstudio is doing this adding)
But that javascript also gets added to vega-embed (using the non-minified for debugging purposes).
It seems to add it there because that part of the code is creating some html and has "head" tags that the method for inserting the javascript probably uses to decide where to insert stuff:
This insertion leads to an error (the console.log error points to that particular section in the vega-embed script).
I think this is a bug on rstudio's part -- it should not insert its javascript snippet into other javascript. I will file an issue in that repo, but will first want to put together a minimal example to share.
from altair.
With update, I still don't see the plots in rstudio viewer (or notebook). Weirdly if I try using same version of vega.js just not minified it seems to show up (had tried that version in hopes it would be easier to debug) in rstudio viewer, although still not in the notebook
I think the notebook issue is some kind of javascript issue and not a print/knit_print issue because I get the white box where the widget should go and then some javascript errors in console window
from altair.
That is weird that the non-minified version of vega.js just works. Do you think we should switch to the non-minified version with the package itself?
Thanks for poking around on the inline issue and throwing light on the javascript. I'll do the same over the weekend, maybe one of us can shake it loose 🙏
from altair.
Nice catch! I am going to need to sit down with a cup of coffee to wrap my head around it. From what I understand so far, the fact that there is a vega-embed snippet is consistent with the superficial question I was asking myself: "why does this work for leaflet, but not for us"?
I agree with you that rstudio should take this into account (assuming this is the culprit). Let me know if I can be of help!
from altair.
I have confirmed that the "head" tags are the issue -- editing the vegaEmbed line with the head tags as:
var header = "<html><he"+"ad>" + sourceHeader + "</he" +"ad><body><pre><code class=\"json\">";
So that the full string is no longer present fixes the issue! 🎉 🎉 🎉
I'll still file a bug with rstudio (assuming this problem is still there when I try the latest daily build of rstudio, which I have yet to do). But in the meantime, would it be okay if I put in a PR with a modified vega-embed that works with the notebook? I can try to make the modification be something that happens programmatically after the download of vega-embed by the rmarkdown in data-raw.
from altair.
🎉 🎉 🎉, indeed! Nicely done!
If I understand correctly, you are denaturing the vega-embed code to avoid the collision. Does this have any effect in the other rendering scenarios like the RStudio viewer pane or R Markdown documents?
It would be great if you could make a PR. As you suggest, it would be nice to have a programmatic download-and-modification. If that turns out to be burdensome, I'm sure it would be fine to modify the manifest to include vega-embed-aschep.js
or the like, making the modification by hand - especially if RStudio make their fix reasonably quickly.
If RStudio aren't able to make a fix quickly, I think it becomes more interesting to have a reproducible fix.
At any rate, please make a PR as you see fit.
Thanks!
from altair.
As far as I can tell the change has no ill effects on other outputs -- the change is to break up the string from "head" into "he" + "ad" (which will get added up into "head" by the javascript) so in theory should have the same exact behavior (but avoid being caught by rstudio's parser for head tags). But am curious as to whether this works on your end!
from altair.
Now that this is merged, I think it remains to agree on a plan to "unwind" this PR (weird as it may sound to say).
I suspect that in the future we should offer the "unmodified" version of the vega-embed code, but that we should continue to offer it for the time being.
Question: If you agree with the premise, what is the "time being"?
Perhaps until the next release of the IDE?
At that time, could we use RStudio.Version()
to generate a message on loading if the IDE is "too old"?
I don't think there is any urgency to these questions. More immediately, thanks again for getting this sorted out!
from altair.
hi @AliciaSchep @ijlyttle - altair in R looks really cool!
just wanted to say that i came across this same issue working on something similar so this was quite helpful. So thanks for this! Since I use this same workaround will give credit for this in the description file if you agree.
from altair.
Hi Matthew,
Thanks for your kind words!
On the question of agreement, of course I defer to @AliciaSchep, who came up with the workaround.
It is great to see more work in this area - I take as an issue on my end to make a link to your work.
One of the things we have planned is to split the package into two (#49), so the renderer would stand apart from the spec-generator. This way, you - or anyone - would be welcome to import/export the rendering functions.
from altair.
@mdequeljoe whatever you feel is appropriate is fine by me! Thanks for sharing your project, looks like an interesting approach.
One thing we could make use of in altair (or the future split-off renderer) @ijlyttle is the "dots" replacement that vl
does (https://github.com/mdequeljoe/vl/blob/master/R/vl_plot.R#L31 and https://github.com/mdequeljoe/vl/blob/master/R/utils.R#L18)... in which case we'll want to credit @mdequeljoe 😄
from altair.
I think this is resolved in vegawidget
from altair.
Related Issues (20)
- Updated to Altair 4.0.1 and charts are not being displayed. HOT 2
- charts not displaying inline for jupyter notebook HOT 2
- Rounding of small values for log scale HOT 4
- Disable max rows HOT 1
- update to Altair 4.1.0
- add github actions
- remove iris references
- Release altair 4.1.1
- Cannot go to the vega editor from an altair plot in Rstudio HOT 2
- update documentation HOT 2
- use Altair 4.2.0
- use vegawidget 0.4
- update actions for check and pkgdown HOT 1
- use CRAN version of vegawidget
- Release altair 4.2.1
- Fix CRAN problems
- fix vignette examples
- Release altair 4.2.2
- update actions
- update URL
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 altair.