Coder Social home page Coder Social logo

Comments (13)

ijlyttle avatar ijlyttle commented on May 30, 2024 1

Progress: Thanks to @AliciaSchep's advice, now renders in RStudio IDE window, but not yet inline in Rmd notebooks.

from altair.

AliciaSchep avatar AliciaSchep commented on May 30, 2024 1

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:

javascript_added

(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).

inserted_javascript_wrong_place

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:

where_it_gets_inserted

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.

AliciaSchep avatar AliciaSchep commented on May 30, 2024

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.

ijlyttle avatar ijlyttle commented on May 30, 2024

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.

ijlyttle avatar ijlyttle commented on May 30, 2024

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.

AliciaSchep avatar AliciaSchep commented on May 30, 2024

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! 🎉 🎉 🎉

notebook_success

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.

ijlyttle avatar ijlyttle commented on May 30, 2024

🎉 🎉 🎉, 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.

AliciaSchep avatar AliciaSchep commented on May 30, 2024

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.

ijlyttle avatar ijlyttle commented on May 30, 2024

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.

mdequeljoe avatar mdequeljoe commented on May 30, 2024

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.

ijlyttle avatar ijlyttle commented on May 30, 2024

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.

AliciaSchep avatar AliciaSchep commented on May 30, 2024

@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.

ijlyttle avatar ijlyttle commented on May 30, 2024

I think this is resolved in vegawidget

from altair.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.