Can a jupyter-notebook contain a link to a LOCAL file? - jupyter-notebook

I'm using markdown in jupyter-notebook (R mode). Is it possible to include a link to a local file? I'm only going to access the notebook locally, so I don't need (or want) to make the local files accessible over the web.
thanks

Related

Azure Databricks: How do we access R Scripts present on DBFS?

I'm new to DataBricks. I am trying to access a .R file that is present in the DBFS storage but I cannot figure out how to do so. Any help is really appreciated.
I can read data from the storage using the file path /dbfs and also source code from the script but I want to make edits to the script.
You need some editor to do that - for example, you can setup RStudio on your cluster and connect to it via RStudio UI - in this case you can edit R files directly on DBFS.
But really, the simplest for you would be to use Databricks CLI fs command to copy the file to your local machine, make changes in the editor of your choice, and upload file back.

Embedding local PDF file in R flexdashboard:runtime:shiny

I need to display a pdf file from my local machine in the dashboard which I have built using R-Flexdashboard (runtime:shiny).
Please help how can I do the same.
shiny::include_graphics("C:/Users/mykum/Documents/R-Flexdashboard/BA-Project/www/Process_Flow.pdf")

How to run a downloaded Jupyter notebook on Google Colaboratory?

I am using Google Colaboratory & github.
I create a new Google Colab notebook, and I clone my github project into it using a simple !git clone <github_link> in the notebook.
Now, I have a Jupyter notebook in my github project that I need to run on Google Colab. How do I do that?
There is not a real need of downloading the notebook. If you already have your Notebook in a GitHub repo, the only thing you need to do is:
Open your Notebook file on GitHub in any browser (So the URL ends in .ipynb).
Change the URL from https://github/full_path_to_your_notebook to https://colab.research.google.com/github/full_path_to_your_notebook
And that should work.
You can upload the notebook to google drive first, then open it from there.
go to drive.google.com
go into directory “Colab Notebooks”
choose “New” > File upload
After uploading, click the new file
Chose “Open with Colaboratory” at the top
The two most practical ways are both through the Google Drive webinterface.
The first method is what #Korakot Choavavanich described.
The advantage of this method is that it provides a Search window to search for your file in your google drive storage.
The second method is even more convenient - and maybe more appropriate for your case:
In the Google Drive webinterface, you navigate to your folder where your file is located - in your case within the cloned github repository.
Then (see screenshot):
right-click on the file | Open with | Colaboratory
Your file is then converted into a colabo notebook automatically (it takes at least half a minute for that).
The advantage with this method is that you can create the colabo file directly in the folder.
My tip is to create a copy of the original jupyter file (I added "COLABO" in the file name) as you will have different code to sync your google drive and save files than in a local jupyter notebook.
One of the way could be that you can connect your google drive with the Colaboraty notebook using the following link:
Link to images within google drive from a colab notebook
Post which you can download your github repo in your google drive location. Then browse through your google drive and open the notebook using Colaboratory itself.
import sys, os
sys.path.append('models/research')
sys.path.append('models/research/object_detection')
It helped me. I was also looking for it, and found it in this COLAB work
https://colab.research.google.com/drive/1EQ3Lt_ez-oKTtVMebh6Tm3XSyPPOHAf3#scrollTo=oC-_mxCxCNP6
The better option I have found is copying the code from each cell and executing the code in colab, if you clone the Github and containing ipynb file in that. By doing this you won't face any difficulties.
Upload the .ipynb file directly in colab. Just go to colab, in the tabs above there should be upload. choose the file and upload there.
It may be a new feature not mentioned in other answers.
But right now Colab allows running jupyter notebooks directly from github, even from private repos.
Login to your google account
Access colab.research.google.com
Select the GitHub tab.
Choose include private repository if needed.
Go through the authentication process in the new opened window
Select from your repos and notebooks
And clone your repo from inside the opened notebook.

Modifying jupyter notebook in init code

Is it possible to modify the contents of a notebook in the notebook startup code? I want to run some init code and add "header" cells to every notebook on a machine based on the code, for instance grab the hash of the current head from a local git repo, or pull a file from S3 to the local file system.
I can put a bunch of scripts, either .py or .ipy in the ~/.ipython/profile_default/startup/ directory and I'd like to modify the notebook that is currently being opened using those scripts (or some other scripts if that's possible).
According to the docs the shell has already been setup when those scripts run, so I'm thinking there should be some way of accessing, at a minimum, the local path of the notebook that was opened. I could then use nbformat (github) to modify the contents.
Alternatively I could use NotebookApp or ContentsManager to possibly modify the running notebook, but I'm not exactly sure how to do that and the notebook docs are pretty light on the actual API for those classes. This might not be possible as the init code is executed in the kernel, which does not know what the front end is, it could be the case that the kernel is connected to a console not to a notebook or to both a notebook and a console.
So
can I access the filename of the current notebook in a startup script?
should I rather be looking to modify the notebook cells through NotebookApp, FileContentsManager or some other internal class?
related
There is an open issue for template files https://github.com/jupyter/notebook/issues/332 -- this is not what I'm looking for, the template files are static, I need to modify the notebook based on the result of a computation

Is there a way to change the file path for an Rstudio project?

I'm using GIT and I note that if I just move the whole folder (or rename it) in windows, that it breaks all the paths. I then end up in an infinite loop of trying to quit Rstudio and Rstudio unable to find the file path to save (or not save).
Is there a way to move the location of the project folder while keeping it still intact?
Sorry, let me make this clearer.
Start Rstudio and create a version-controlled project (I'm using GIT)
Realize that you put the project in the wrong folder of your computer
Move the project to the new folder by (a) moving the Rstudio and GIT files to another location using windows explorer. (breaking all the links) or (b) start a new project in the 'correct' location. (losing the versions of your edits).
With RStudio closed, I moved the project folder (using Windows Explorer) to a new location. My RStudio project opened fine from there. I made an edit and pushed it to Github.
If you use the here package on Cran you won't have to update any links.
If you use GitHub Desktop, it will detect that the project has been moved and allow you to locate (set) it to a different folder.

Resources