Skip to content

Conversation

marimeireles
Copy link
Contributor

Hey, I was running the examples and noticed the JS part of this one wasn't running anymore because it couldn't find the npm d3.
This is a fix. :)

@fpliger fpliger requested a review from mattpap May 11, 2022 20:46
@mattpap
Copy link
Contributor

mattpap commented May 11, 2022

This example works for me on most recent main (as of 73a0d9b). Note that d3 import is defined by the importmap.

<script type="importmap">
{
  "imports": {
    "d3": "https://cdn.skypack.dev/d3@7"
  }
}
</script>

located above the py-script. If ESM import mapping doesn't work in some context, then the underlying bug needs to be fixed, not the import changed.

@mattpap
Copy link
Contributor

mattpap commented May 11, 2022

Actually, import maps are not widely supported (https://caniuse.com/?search=importmap). Only chromium-based browsers support it. That's unfortunate, given that one of the points for this example was to show this off. There seems to be a polyfill (https://github.com/guybedford/es-module-shims) available, so we may want to use this instead, though I didn't test it.

@marimeireles
Copy link
Contributor Author

I see.
I use Firefox and for me didn't work at all, so I thought it was just broken. Should have tested in different browsers.

@verhulstm
Copy link
Contributor

verhulstm commented May 15, 2022

i have been thinking about rebuilding all the examples without import maps. i dont want to showcase js

i want to showcase python, with light and very simple js. we dont want beginners to have to learn js and js patterns

@marimeireles
Copy link
Contributor Author

I agree with @verhulstm take on this.
I think it would be nice to have complex examples to showcase how far you can go using the power of both langs. e.g there are some people asking for examples of pyscript + react. I think that's really cool but I also think it's a bit out of our scope, specially for now.
What are your ideas on this topic @mattpap?

@tildebyte
Copy link

FWIW: FF has partial support for the most recent import stuff. I'm using es-module-shims here, and indeed it gives full support for at least FF.

@tildebyte
Copy link

I don't mean to threadjack here, but given "I think it would be nice to have complex examples to showcase how far you can go using the power of both langs", is there a process for submitting examples/demos? The three.js thing I'm working on[1] is all Python, driving the three.js library. It's not overly complex and (I think, anyway :) ) shows off a fair number of Python features, some interesting pyscript features (referring to a main script using pyscript tags, including external py files), as well as how to work with an existing JS lib in a Pythonic way.

[1] It works; I'm currently in that infinitely recursive "tweak the aesthetics" phase.

@fpliger
Copy link
Contributor

fpliger commented May 17, 2022

There is value in this example. D3 has been a desired project in the Python Viz ecosystem for ages ... Now, removing complexity makes a lot of sense in general but if it's not possible in this case, I'd keep the example and 1. Try the polyfill or 2. Point out that works only on Chrome.

@tildebyte no problem, thanks for your question. We are working on a process to better welcome community examples. In the meantime I'd suggest to open a PR if you want to out the example in front of others to review

@fpliger fpliger merged commit 4fe603b into pyscript:main May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants