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

In jupyter, display(HTML(html_code)) only renders correctly the first time it's run #2

Open
thorwhalen opened this issue Dec 23, 2022 · 4 comments

Comments

@thorwhalen
Copy link

See this video for details.

@Stukova
Copy link

Stukova commented Dec 23, 2022

@thorwhalen Sorry, I didn't mention that the jupyter notebook I made is for demonstration purposes only. When I created the javascript Cosmos bundle, I wanted to make sure it worked with the IPython.display library. I ran into the same problem and forgot to mention it.
The problem is that when display(HTML(html_code)) is executed more than once, JS runs the script again and tries to create const data again, which is not allowed in JS (see screen recording below).
I think the data will not be created in JS, but in python and somehow converted in the Cosmos python library/wrapper/widget, so there won't be a problem with duplicate const declarations. The cosmos and canvas instances, I assume, will be created once in the python Cosmos library which will be imported once in the jupyter notebook or in the python script as well.

jupyter.Cosmos.issue.mp4

@thorwhalen
Copy link
Author

So what can we do about it?

I took your stuff and made a function that would recreate the steps from data that would come from python. But as you see, since I'm using the javascript you created as the template, I have the same problem.

If I had to hack it, I'd have my template create the data variable under a random name every time, so as to not collide with previous names. But it seems quite hacky and would probably fill the RAM.

Could we define the data without the const type and overwrite it every time?

What's the best practice for this that you find in other python binders for JS?

@thorwhalen
Copy link
Author

See the py_cosmograph repo (and cosmograph pypi package).

With it I can do this:

image

But as I mentioned, will have the same problem (see code -- namely my use of an html_template where I inject the data).

@thorwhalen
Copy link
Author

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

No branches or pull requests

2 participants