I am learning python using a course. The course material can be found on the links like the following one:
http://faculty.washington.edu/sbrunton/me564/python/Python_Introduction.ipynb
I'd like to have the jupyter notebook when I go to the link but it shows the raw python file. How can I export the jupyter notebook from such links?
Thanks in advance for any help.
You can just open an already created jupyter notebook (the file with .ipynb) in a notepad and replace its text from the text in your link.
Steps
Create a totally new jupyter notebook project.
Go to the file location and open it with notepad
Remove all the content from the notepad
Replace it with the content in your link https://faculty.washington.edu/sbrunton/me564/python/Python_Introduction.ipynb
Save the notepad and close it.
Open the same file as a notebook using Jupyter notebook or Google Colab
You can copy the raw content and paste to local new file. File extension should
be .ipynb .Then you can open in jupyter lab or notebook.
Go to nbviewer.org, paste in the URL, and press 'Go!'. You'll then be redirected to here which is a page that has the following URL:
https://nbviewer.org/url/faculty.washington.edu/sbrunton/me564/python/Python_Introduction.ipynb
At that URL is the notebook rendering you seek. (nbviewer will even display some 'interactive' items such as Plotly plots and animated matplotlib plots backed by frames, examples here and here, respectively.)
Right-clicking the download icon in the upper right side of the notebook rendering there and selecting Save link As... will allow you to save the .ipynb file to your local machine. (You can do similar from the original page link, but there you have to edit the name. No editing of the name necessary this way for your link!)
If you examine the URL generated by the form, you'll note that there is a pattern based on what you provided. And so you could just change the original portion of the link you provided from http://... to https://nbviewer.org/url/... and go to the notebook rendering directly without the step of filling out the form.
If the page had been hosted at GitHub or another repository that MyBinder.org can use, you'd have in the upper right corner an additional icon looking like three rings on the nbviewer rendered page that could be clicked to open it as an active Jupyter notebook right in your browser without needing to login as it would be served vis MyBinder.org. The pages I link to for the Plotly plots and animation have this icon as an option.
Related
I am in Visual Studio Code and I have created the following jupyter notebook:
I would like to know how to remove or modify the pdf header (circled in red below) produced when I export this notebook to pdf with VSCode.
I know this is a similar header to a latex document produced with \maketitle, but I don't know how to remove it or how to change the title, add authors or change the date. I would also like to know how to reduce the margins of the pdf produced (in my latex document I use \geometry for).
Thanks for your help :
In fact, the best way to convert jupyter files to PDF is not through vsocd or notepad. We can open jupyter files through Chrome browser, and then convert them to PDF by printing, so that no title can be adjusted, and row spacing can be adjusted in print.
I didn't find a satisfying solution: you would have to edit the notebook's metadata (in JSON).
For now, I:
export the notebook as LaTeX source (e.g. jupyter-nbconvert --to latex my_notebook.ipynb)
edit the generated .tex file to adjust title and author.
compile it to pdf (pdflatex or your favorite tool).
Hi there if anyone can answer this.
I am trying to read csv data from kaggle https://www.kaggle.com/stackoverflow/stack-overflow-2018-developer-survey in pycharm and online jupyter notebook but I can not find a command how to read.
I know how to read data if it is in my computer but not know from the online web. I will so grateful if anyone can help me in that.
From the page you linked to, you have a couple of options.
Create a notebook and the input files will be automatically included. Run the first cell that's generated for you and it will print out the paths to the input files. You can use Pandas read_csv in the notebook to load the data using those paths.
Expand the input folder in the Data pane (top right of the notebook), click on the file you want and look for the Download link at the top right of the data grid.
Is there a way to display a dataframe in a Jupyter notebook such that clicking cells opens a Windows explorer (or any other native explorer) in a given directory?
I tried
def make_clickable(url):
return f'{url}'
df = pd.DataFrame({'dir': '.'}, index=[0])
styled = df.style.format({'dir': make_clickable})
display(styled)
df = pd.DataFrame({'dir': 'file:///C:/'}, index=[0])
styled = df.style.format({'dir': make_clickable})
display(styled)
The former opens a new browser tab in which the Jupyter tree is displayed (at the correct relative location, if I replace . by another relative path).
The latter doesn't do anything. If I right-click open in a new tab, it gives about blank#blocked and if I copy and paste it in a new tab address line, it shows the browser built in explorer, not the Windows explorer.
I tried replacing _blank by _explorer.exe but that doesn't change anything for either variant.
Thus, both options are far from what I want.
(I know, security... but, this is for an in-house tool in a a completely off-line setting)
I know it is somehow possible to open explorers from the browser, because I can just use os.startfile in a Jupyter cell, so I was thinking maybe there is a way to execute arbitrary code when cells of a dataframe are clicked? Maybe this requires some sort of widget?
I could always write an entire Python GUI of course, but I'd really rather not.
I am a bit late but I finally figured it out. Javascript itself is unable to open file explorer for security reasons. However javascript can execute python code inside Jupyter notebook(Jupyter.notebook.kernel.execute) and python can open windows explorer using(os.startfile('.'),subprocess.run etc.).
Below is the code. The linux one works fine as intended but with windows the explorer opens but doesn't move into user focus it also shows the orange beeping light behind the icon show it should be fine.
import pandas as pd
import os
import subprocess
windowsv1 = """
<p onclick="Jupyter.notebook.kernel.execute(`os.startfile('C:\\Users')`)">File Explorer.</p>
"""
windowsv2 = """
<p onclick="Jupyter.notebook.kernel.execute(`subprocess.run(['explorer', 'C:\\Users'])`)">File Explorer.</p>
"""
linux = """
<p onclick="Jupyter.notebook.kernel.execute(`subprocess.call([opener, r'/home/equinox'])`)">File Explorer.</p>
"""
def make_clickable(url):
return windowsv2
df = pd.DataFrame({'dir': '.'}, index=[0])
styled = df.style.format({'dir': make_clickable})
display(styled)
I am not 100% on this but I think this will depend on the browser you are using. Furthermore, I think most browsers will block this kind of behavior and not allow a web page link to open your file browser.
Please, someone, correct me if I'm wrong.
EDIT 2020-08-15
It is possible to do it if you install a Chrome Browser extension.
Just follow the below link. After your code worked for me.
https://www.alphr.com/browse-and-open-folders-files-chrome/
Scroll down to Title "Open Any Local File From Chrome".
Follow all the steps
Don't forget to restart Chrome after installing the browser extension (and the extra installation file)
I'm using Jupyter notebook to write up my report using Markdown and Python to make widgets.
On the Jupyter notebook, when I click on "file", then "Download as" HTML(.html), it converts my notebook.
In the html, I noticed that none of my widgets appear, and any images I've attached by markdown as <img src="myimagehere.png"> also disappear.
Only the actual code, " appears, not the image itself.
P.S. I also just noticed that the markdown mathematical notation like Latex suddenly appears as only code in html. So three problems in one, wonderful.
Been struggling to find an answer/solution. Can anyone please help? Many thanks.
When I browse my file system through a jupyter notebook server I can view and edit HTML and other text files in addition to ipynb files. However I want to view the files as rendered HTML instead of viewing them as a editable HTML.
In other words, how can I make a jupyter notebook server serve static content?
It already does, under /files. For example, when https://tmp39.tmpnb.org/user/IgoeEDdRLpRG/edit/featured/pandas-cookbook/README.md is the URL for editing a file, https://tmp39.tmpnb.org/user/IgoeEDdRLpRG/files/featured/pandas-cookbook/README.md is that file served up as-is (the first two segments of this example file path are specific to tmpnb servers).