how to insert a link to a local file into a markdown cell? - jupyter-notebook

Dear ipython notebook users,
I want to insert a link to a local file located in the notebook directory, and no, it is not an image (the only example I've found). I want to insert this link within a markdown cell.
When clicked on the link, the file is to be opened with a local application (in this case, a molecule viewer)
I've tried to come up with the correct syntax, but no luck. Please, any help is greatly appreciated.

I want to insert a link to a local file located in the notebook directory
I want to insert this link within a markdown cell.
The path need to be relative to where the server has been started, and prefixed with files/.
e.g: [my molecule](files/molecules/ethanol.mol)
the file is to be opened with a local application (in this case, a molecule viewer)
Not possible unless your application support custom links protocol like the itunes:// or apt-get:// one. the best that can append is that on link click you will be prompted to download the file. (keep in mind that the server can be on a different machine thant your browser)

completenting the answer of Matt, it will work only in you import FileLink
from IPython.display import FileLink, FileLinks
FileLink('path_to_file/filename.extension')
Then in a markdown cell insert your links waterBox30.pdb

Related

How to show image from folder in google colab

How can I show the pictures from folder figures in google colab inline in a markdown cell?
I have the following structure of notebooks on my local drive.
figures
- pic1.png
- pic2.png
- ...
Notebook1.ipynb
Notebook2.ipynb
etc.
After opening a Notebook in google colab and uploading the figures folder, I checked that the folder with pictures is actually uploaded. It is.
I then tried the following in a markdown cell:
![Pic1](figures/pic1.png)
This apparently doesn't work in google colab.
How did Jake VanderPlas do this here? Apparently he didn't even upload the pictures into a folder "figures" but still uses the following line in markdown
![Broadcasting Visual](figures/02.05-broadcasting.png) in the above link (scroll down to see a picture on numpy arrays).
Any help is appreciated!
Thanks!
GitHib image references are resolved relative to the repo.
For notebooks stored in Drive, you'll need to embed the image in the notebook. Here's an example:
https://colab.research.google.com/drive/1jWHKR6rhhyZtUulttBD6Pxd_AJhgtVaV
The key bit is the Image display helper, applied to a local file–
from IPython.display import Image
Image('220px-TensorFlowLogo.svg.png')
Here is another way to show it.
##markdown Fig.1. Pic1 demo
import matplotlib.pyplot as plt
pic_name = '/content/drive/MyDrive/pic1.png'
image=plt.imread(pic_name)
fig=plt.figure(figsize=(20,30))
_=plt.imshow(image)
_=plt.axis('off')
Markdown tag shows text, which allows code hiding from the report (if that is your end goal).
Once you upload your local image to your Google Colab filesystem (click the folder icon on the upper left of your notebook that says "files", then upload it), you can use the IPython code to display it. You get the path link by right-clicking on the image after you uploaded it that says "copy path". Put the whole link in quotes.
from IPython import display
display.Image("/content/my-image.png")

Hyperlink that can lead to a pdf in Jupyter notebook

I'm working with Jupyter notebook and have a question in mind:
If I want to markdown an HTML file or any website, I can just simply do
[name-of-the-website](address-here)
and it will create a link to the page that I want to reference
My question is
Are there any markdown code for PDF reference
IS the code the same with HTML reference (whenver I click into the markdown link, It will create a new tab which can download the file to the computer)
P/s: I'm not talking about coverting the notebook into PDF file
I have found out an answer:
Go to the file PDF that you want to download, for example I want to download this PDF file
Ideas:
Because there should be a HTML link to download the document, if one can find this link, then can proceed to normal markdown HTML file in Jupyter Notebook
Steps:
On the browser, right-click that PDF download link, and then choose Inspect Element (Q) (on Firefox or any browser in use)
It is then open the console that will shown the download HTML file like shown:
href="http://www.montefiore.ulg.ac.be/services/stochastic/pubs/2009/DMWG09/dumont-visapp09-shortpaper.pdf"
One can proceed with normal markdown in Jupyter Notebook
This works for me:
ref.
This is a relative path to the file.

Link to python file in Jupyter notebook markup cell

Suppose the following: I locally execute the jupyter-notebook server in my home directory.
I have the following files in ~/temp/jupyter_link:
index.ipynb python_file.py
In a markup cell in index.ipynb I want to create a link to python_file.py. This link should open python_file.py with the jupyter-notebook editor. I can do that with:
[python_file](https://localhost:8888/edit/temp/jupyter_link/python_file.py)
However, this link contains the absolute path of python_file.py. I want to use the relative path (with the base directory being the one from index.ipynb). I can create a link using the relative path with:
[python_file](python_file.py)
However, if I click this link I'm asked to download the file and it's not opened with the jupyter-notebook editor.
Is it possible to create a link that opens the python file with the jupyter-notebook editor but that uses a relative path? The pseudo-code I imagine would be something like:
[python_file](edit:python_file.py)
Inspired by #Ivan's answer I might add that
[python_file](/edit/temp/jupyter_link/python_file.py)
also opens the editor. That removes the host name from the link, but still does not give me a relative link.
The following seems to work (nowadays?) in Jupyter 5.4.1 and Jupyterlab 0.32.1:
[python_file](./python_file.py)
You already noted how this is solved in your question, but I kinda missed that
[python_file](/edit/temp/jupyter_link/python_file.py)
is actually the best answer. I figured it out after I found how to make the relative link and I was almost done writing this. So here is an explanation of how to do the relative and why the above link is actually better.
From the index.ipynb use the Jupyter file>open menu to navigate to the python_file.py. Look at it's address, in this case it should be something like
https://localhost:8888/edit/temp/jupyter_link/python_file.py
Now look at your index file's address, should be something like:
https://localhost:8888/notebooks/temp/jupyter_link/index.ipynb
To get to the /edit directory from the /notebooks you have to back out a few directories with ... The link should be something like
[python_file](../../edit/temp/jupyter_link/python_file.py)
However, you will always be backing up to the base of the Jupyter server directory to go from /notebooks into /edit, so just forget about counting ../ and just start with /edit.

How to change working directory via extension in Adobe brackets

Given a file or path - I can use FileUtils (or similar) to work with files. I'd like to be able to alter the current working directory in my extension.
I see in node.js there is process.chdir(directory) but I am unable to access that object.
Is there any other way to change the current working directory.
I am trying to create a simple plugin that when you open the file dialog, the directory your file listing is the same as the currently opened file. The simple implementation being:
MainViewManager.on("currentFileChange", function (e, newFile) {
process.chdir(newFile.parentPath); // This is my FAIL
});
Brackets, like many GUI apps, doesn't use the current working directory very much once it's up and running. So there is probably a different way to accomplish what you're looking for.
When you say...
when you open the file dialog, the directory your file listing is the same as the currently opened file.
...do you mean you want the file tree on the left side of the window to change? If so, try the ProjectManager.openProject() API.
...or do you mean you want to open a file-picker dialog box (like what you see when you choose File > Open in the menu)? If so, you can use FileSystem.showOpenDialog() - the 4th argument is the directory to show when the dialog is first opened.

Opening an Excel .xlsx file in IE and following its embedded hyperlinks back to file server

I have an intranet site that lets users open files in the browser (by prompting for download). One of these files is an .xlsx workbook that contains hyperlinks which point to different locations of files (.pdfs, .docs) on the file server in which the .xlsx workbook is located.
It seems the file server path to the workbook is replaced by a "Temporary Internet Files/Content.IE5/" path, leading to the warning "cannot open the specified file" in Excel.
I tried downloading the Excel document first and then following the links, but they're still opening in the temp internet location
EDIT:
For instance, when hovering over the hyperlinks in excel they read: "file:///C:\Documents And Settings\%username%\Local Settings\Temporary Internet files\Content.IE5\40WSS3CB\" + filename
when they should read: "file:///\servername\Departments\Read\" + filename
How can I still open the excel file in the browser and retain the hyperlinks inside and have them not be replaced by the temporary internet files path?
can someone point me in the right direction ? Thanks!
I did some testing, and it almost comes from the way you store links. If you browse through the dialog of Insert hyperlink, then you will end with relative urls. That is, the common base is stored as a reference to the current xlsx file path, and the remainder is stored and displayed as link.
You are totally in the issue Richard Hare mentions, so following the procedure from the microsoft support site should help. It did the trick on my test at least.
UPDATE to sum up down.with.the.bass comments :
One option to solve this, if doable, is to open xlsx file from its network share location and not through the website. If it is forbidden for whatever reason, you may be able to update the links using a macro.
Do you have an option like "Update links on save" enabled?
In an earlier version of Excel it was set in Tools, Options, General-tab, Web Options-button, Files-tab.
Try unchecking it and resaving the document.
I just did in my server the same task (the one I understood):
Uploaded the hyperlink to some asp.net webpage.
<p>
test<br />
</p>
The "book1.xlsx" file has inside a cell which refers (hyperlinks) to some share directory (i.e \\NHSTXX1\TEST\MS OFFICE EXCEL - \\SERVERNAME\FOLDER\OTHER FOLDER )
And when clicked the hyperlinked cell, it opened the share directory I was looking for.
I tried with Firefox.
hope this help
Hyperlinks shouldn't just mysteriously change. I saved an excel file with a hyperlink in it - opened it with html - saved it - open it in excel again - and the link stays the same. So I'm not sure how this could be happening to you(if I understand your situation correctly).

Resources