2 years ago

#32028

test-img

JFerro

Open a url from a jupyter lab notebook rendered with voila in a new Chrome Tab

I work in a JupyterHub environment where I use to render applications with voila.

One of this particular applications is supposed to be a kind of Launcher from where a user can launch (open) a particular url web in another chrome tab.

I use the following code:

import ipyvuetify as vue
from ipywidgets import Output
from IPython.display import Javascript

out=Output()
b = vue.Btn(color='primary',children=['open tabs'])
def on_click(widget, event, data):
    # generate an URL
    url_nyt    = "https://www.nytimes.com/"
    url_news   = "https://www.cnn.com"
    with out:
        print('go')
        # VEEEEEEEERRRRY important: inside out
        display(Javascript(f'window.open("{url_nyt}");'))
        print('first')
    with out:
        display(Javascript(f'window.open("{url_news}");'))
        print('second')
# this does not work neither: display(Javascript(f'window.open("{url_nyt}");window.open("{url_news}")'))
        
b.on_event('click', on_click)
display(b,out)

This works only with the first url. What happens is that indeed a new tab opens and the nyt web site opens there but there is no second tab open. Nevertheless in the output widget is possible to see "second" so the second display was run, did not give an error, but did not work.

Any idea why that is like this? Or any workaround? Is it necessary to open the tab in the background? how?

btw, the library webbrowser does not work since this is jupyterHub (in a remote server) and not a local jupyter lab distribution.

thanks

python

ipywidgets

jupyterhub

voila

ipyvuetify

0 Answers

Your Answer

Accepted video resources