Reputation: 5755
I'm running Jupyter notebook on a server and executing it from a client computer. In Rstudio server, one can programmably open a server-side file in a new tab via file.show
. This is sometimes very convenient. For example, I have a script that processes a rather large image. Because of its size I don't want it to show directly in the output panel, rather I want to view it in a new tab. In Rstudio server I would normally do:
... image processing code ....
ggsave('temp.png')
file.show('temp.png')
This will automatically pop up the new image in a new tab once the script is finished.
Is it possible to do something similar in Jupyter?
I noticed that I could achieve this by clicking the image file in the built-in file browser, but I wonder if this could be programmed.
Similarly, is it possible to programmably open a webpage in a new tab like browseURL
in Rstudio server? Note that webbrowser.open(url)
doesn't quite do it because it tries to open a local browser, which in the server-client scenario will not open the new tab on the client side.
Upvotes: 1
Views: 784
Reputation: 38668
You can make a link. Relative URLs will open in a new browser tab. Files are served relative to the directory containing the notebook you are currently working on.
In Python:
from IPython.display import display, HTML
display(HTML('<a href="temp.png">see image</a>'))
Opening new tabs programmatically often triggers pop-up blockers, but publishing a link that the user clicks should be reliable.
Upvotes: 2