Jupyter Notebook support #733
Replies: 6 comments 5 replies
-
Currently it fails because "asyncio.run() cannot be called from a running event loop". Install and start jupyter: pip install jupyter
jupyter notebook Example code: from nicegui import ui
ui.label('Hello')
ui.run(reload=False) Output:
|
Beta Was this translation helpful? Give feedback.
-
Ah that looks like a FastAPI/uvicorn problem. Maybe https://stackoverflow.com/a/74071421/364388 helps? |
Beta Was this translation helpful? Give feedback.
-
Great, this works: from nicegui import ui
import nest_asyncio
ui.label('Hello')
nest_asyncio.apply()
ui.run(reload=False) However, starting and stopping the app or kernel is a bit weird. Actually I'm not sure what to expect. What would you even use NiceGUI for within a Jupyter notebook? |
Beta Was this translation helpful? Give feedback.
-
Thats soo cool. Would you like to create a small pull-request which adds this example in https://github.com/zauberzeug/nicegui/tree/main/examples, @gexahedron? That way your contribution would be "official" in the commit history :-) |
Beta Was this translation helpful? Give feedback.
-
@falkoschindler What would it take so that I could have an experience like solara, where I can see the element right under the code cell? ie not in a separate browser from nicegui import UI
ui.label("hi") and then that element was displayed a la a jupyterwidget underneath the cell? very rough idea of how it could work?
Probably some architectural things in the way, but I love using the tight feedback loop of a notebook for prototyping components and the data that they depend on/modify. |
Beta Was this translation helpful? Give feedback.
-
How about having async def run_aysnc(...):
...
await Server(config).serve() Then from jupyter simply say await ui.run_async() |
Beta Was this translation helpful? Give feedback.
-
It would be great if NiceGUI could be used in Jupyter notebooks. Pull-request are more than welcome!
Beta Was this translation helpful? Give feedback.
All reactions