-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add offline ChartWidget based on AnyWidget #3108
Changes from 2 commits
6ab0ccc
246e102
99a5da2
b5657b7
8359e18
15937cf
134248b
b44d4a7
24c2427
ef0e833
7f25f3d
37bdb6a
11a8e17
eb417c9
8984ccc
7a633d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,4 +74,5 @@ Untitled*.ipynb | |
.vscode | ||
|
||
# hatch, doc generation | ||
data.json | ||
data.json | ||
/widget/node_modules/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import anywidget # type: ignore | ||
import traitlets | ||
import pathlib | ||
|
||
_here = pathlib.Path(__file__).parent | ||
|
||
|
||
class ChartWidget(anywidget.AnyWidget): | ||
_esm = _here / "static" / "index.js" | ||
spec = traitlets.Unicode().tag(sync=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't spec also a dict? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think it could be. This was just copied from the blog post. At this point I'm only really looking for feedback on the the project layout. The Python There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I still feel this could live in ipyvega since there is nothing that is strictly Altair specific in the renderer but I don’t feel strong either way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My hope is, but please correct me if I'm wrong here, that by incorporating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to deprecate ipyvega when this is ready then? I'd think so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @manzt, what does it take to write an anywidget to a self-contained html file? I may be mis-remembering, but I thought that was something that you said was possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, I think this could cover the same use-cases as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to use use the chart_widget = ChartWidget(...)
from ipywidgets.embed import embed_minimal_html
embed_minimal_html("chart.html", views=[chart_widget], title="my chart") But this doesn't seem to be working for any third-party widgets i've tested at the moment... I'll try to have a look and figure out what's going on. |
||
selection = traitlets.Dict().tag(sync=True) |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ChartWidget build instructions | ||
First, [install node.js 18](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) | ||
|
||
Then build the JavaScript portion of `ChartWidget` widget with: | ||
``` | ||
cd widget/ | ||
npm install | ||
npm run build | ||
``` | ||
|
||
This will write a file to `altair/widget/static/index.js`, which is specified as the `_esm` property of the `ChartWidget` [AnyWidget](https://anywidget.dev/). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh interesting, are anywidget's types not working with mypy? maybe I forget a
py.typed
?