Skip to content
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

serving outside of jupyter/nteract #96

Open
Casyfill opened this issue Jun 5, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@Casyfill
Copy link

commented Jun 5, 2019

is there any way right now to serve the vdom outside of the notebook? Can't find that in the docs

@rmorshea

This comment has been minimized.

Copy link
Contributor

commented Jun 5, 2019

@Casyfill I wrote https://github.com/rmorshea/idom to do just this - let me know what you think.

note: there are some slight differences in the event spec that I hope to get merged here soon.

You can try it out here: Binder

@Casyfill

This comment has been minimized.

Copy link
Author

commented Jun 6, 2019

Thanks! It looks pretty cool (btw the mybynder example does not work ,raising

AttributeError: 'dict' object has no attribute 'unmount'

on any interactive execution.

But I was looking for the exact use of vdom package - is it possible?

@rmorshea

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

@Casyfill That error is curious, I don’t seem to see that when I run it. Maybe a concurrency problem? Can you post an issue with the stack trace?

And unfortunately vdom is pretty basic and relies on the notebook for rendering. However I wrote idom in such a way that it would be compatible with vdom’s model specification (with the exception of event handlers, for now). As a result, you should be able to use vdom with idom, so long as you dont use event handlers from the vdom package (though I haven’t tested this recently).

EDIT: You are able to turn VDOM objects into static HTML via VDOM.to_html. While event handlers are part of the VDOM spec to_html ignores them.

@rgbkrk

This comment has been minimized.

Copy link
Member

commented Jun 6, 2019

You can serialize vdom to html using to_html on a vdom node:

In [1]: from vdom import div, h1, p, a

In [2]: layout = div(
   ...:   h1("Example"),
   ...:   p("Hello ", a("world", href="http://example.com"), "!")
   ...: )

In [4]: layout.to_html()
Out[4]: '<div><h1>Example</h1><p>Hello <a href="http://example.com">world</a>!</p></div>'

I can't recall if that's only on master or if we've shipped with that.

@rmorshea

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

@rgbkrk it's in the latest release.

@Casyfill it probably goes without saying, but to_html is static HTML so it'll serve your needs so long as you don't require event handlers.

If you do want event handlers you should be able to use vdom inside of idom:

@idom.element
async def MyComponent(self):
    return vdom.p("hello world")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.