-
Notifications
You must be signed in to change notification settings - Fork 0
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
why cannot I get the url in one cell ? #2
Comments
Because you need to instantiate the widget. That is what this does: w This cannot work in a Python script because it is a Jupyter notebook feature. url = None
async def foo():
global url
w = Url()
display(w)
url = await w.get_url()
asyncio.ensure_future(foo())
|
so using |
It's displaying the widget |
ok, then If i want to get the url in a notebook let's say like this one: w = Url()
w
How can I launch it in voila ? |
Voilà is another beast, it will launch all the cells one after the other, so the URL might not be retrieved from the front-end when you do url = None
async def foo():
global url
w = Url()
display(w)
url = await w.get_url()
await asyncio.ensure_future(foo()) |
Unfortunately for me it's the beast I need to focus on ;-)
arf ok so I tried your last piece of code and even in a jupyter notebook it awaits forever. It seems that the widget cannot be instanciated if I don't leave the cell |
Ah yes, you're right, it's deadlocking. See also:
One solution could be to use akernel. |
thank you for the links, I'll explore the solutions and share what work for me before closing the issue |
Take a look at https://github.com/Kirill888/jupyter-ui-poll edited to add example using this package now i have my install issues sorted out. from ipyurl import Url
from IPython.display import display
from jupyter_ui_poll import run_ui_poll_loop
def window_url():
"""returns the url for the window that jupyter is running in"""
w = Url()
display(w)
func = lambda: None if w.url == "" else w.url
url = run_ui_poll_loop(func)
return url out of interest the same can also be done with ipyleaflet providing the url import ipyleaflet
from IPython.display import display
from jupyter_ui_poll import run_ui_poll_loop
def window_url():
"""returns the url for the window that jupyter is running in"""
m = ipyleaflet.Map(zoom=0)
m.layout.display = "none"
display(m)
func = lambda: None if m.window_url == "" else m.window_url
url = run_ui_poll_loop(func)
m.close()
return url |
thanks @artttt for the suggestions. I think with this + @davidbrochart insight, I have everything I need to make it work from my side. |
In the example the workflow is the following :
I tested it on my end and it works as expected.
Now if i try to run:
in 1 cell, I get
''
as a result. Why isn't it working in one cell (and by extension in a python script) ?The text was updated successfully, but these errors were encountered: