Automatically generate IJulia notebooks - julia

Recently I learned, that using python it is possible to generate IPython notebooks automatically. This looks like a cool feature and I would like to use it for some automatic report generation. However with julia instead of python.
So is there some clean/recommended way of automatically creating IJulia notebooks using julia?

It should be posible to do this from Julia via the PyCall package:
http://nbviewer.ipython.org/gist/Ismael-VC/4c4fcee41b8761af9673
However I got an exception at Out [8]. I've already opened a new issue for this:
https://github.com/stevengj/PyCall.jl/issues/164

Related

Jupyter MathJax Physics package

MathJax3 includes a port of the physics package, which I would like to use inside jupyter notebook / lab.
What are the steps necessary to use this extension? Can it be done without writing custom config files (important for collaboration)?
I tried installing the MathJax3 renderer for jupyter, but it seems that it does not recognize the \require command used to enable the extension. Another user already formulated an issue on github in September, but with no answers yet unfortunately.

JuliaPro: import Jupiter notebook

I usually use Jupyter to have my interactive environment with Julia, now I am switching to JuliaPro, as they claim it is the fastest and easiest way of Julia programming. But, I cannot upload my .ipynb notebooks on JuliaPro. Are they compatible with each other? How can I work with my notebooks on JuliaPro? Thanks!
As was explained in the comments, the .ipynb file format was designed to be rendered in a browser, while Juno/Atom is a text editor that expects a plain text file for display. In general therefore you wouldn't be able to directly use an .ipynb file in Juno.
There is however an option to convert your notebooks to .jl scripts, which is exactly what Juno is expecting: in your Jupyter notebook click on File > Download as > Julia (.jl) (see below)
There's also an answer here that discusses a command line option if you need to batch convert a lot of files.
Also note that your choice of editor / programming environment is unrelated to the version of Julia you're using - while JuliaPro ships with Juno as standard (or potentially the Julia VS Code extension in future), nothing's keeping you from just doing using Pkg; Pkg.add("IJulia"); using IJulia; notebook() in your JuliaPro installation and continuing to work on your notebooks in Jupyter.

How to set Julia Environment for IJulia Jupyter notebook?

I am encountering package compatibility issues within my global Julia environment for specific packages I want to use in a Jupyter notebook. Is there a way to tell IJulia to use a different environment instead of my global one?
The default IJulia kernel sets --project=#. so the most convenient way (IMO) is to just keep your project in the same folder as the notebook. The result is that the correct project is used from the start and you don't have to worry about activating it while in the notebook.
You can always start up a notebook, and within a cell run
using Pkg
Pkg.activate("./path/to/folder")
When starting the notebook type:
notebook(dir="/path/to/your/environment/")
This will launch Jupyter notebook loading the environment (Project.toml) in the directory that you have specified. If there is no Project.toml in that directory, the default (global) environment will be used.
Depending on the complexity of your setup, you might want to consider Lmod
I use this with a module hierarchy: 1. Core module, 2. Compiler modules, MPI modules.
With this, its possible to quickly switch between difference branches.

unexpected input in "%load_ext rpy2.ipython" in R - ipython

I am new to R and trying to execute the code in this site but unfortunately, I am experiencing this error "Error: unexpected input in "%load_ext rpy2.ipython"" when entering "%load_ext rpy2.ipython" in the R console and I tried searching google for answers but no luck.
Any help would be appreciated. Thank you in advance.
rpy2.ipython is an extension for ipython, and Jupyter, when you use the IPython kernel. Not for R. What you linked to is using IPython and calling into R from IPython, not calling in Python from within R. Not sure why they do that in what you linked, from a quick read they should use a R kernel, which would work without saying %%R each time.
So you should be able to reproduce what's there by not loading the rpy2 magic, skipping the %%R prefixes.
If you want to reproduce exactly you will need to install IPython/jupyter and run the code from the Python console.

Can I use variables on an IPython notebook markup cell?

I have an IPython notebook and I would like to use one of my variables inside a markup cell. Is this even possible? If so, how do you do it?
If you don't mind a code cell that does the job, there is a possibility without adding any extensions.
from IPython.display import Markdown as md
fr=2 #GHz
md("$f_r = %i$ GHz"%(fr))
This will show a markdown cell in a nicely LaTeX formatted output
Currently, this is not possible, however there is a large discussion on this topic here https://github.com/ipython/ipython/pull/2592. The PR is currently closed, but a corresponding issue is opened https://github.com/ipython/ipython/issues/2958 and marked as wishlist.
Update
In the meantime an IPython extension has appeared which allows to render python variables in markdown cells. This extension is part of the IPython notebook extensions and works with IPython 2.x and 3.x. For a detailed description see the wiki page.
It is not officially supported, but installing the python markdown extension will allow you to do so. It is part of the nbextensions, for which you will find installation instructions on their github page. Make sure you'll enable the python markdown extension using a jupyter command or the extension configurator.
Calling python variables then should work with the {{var-name}} syntax, which is described in the readme of the corresponding github page (linked in the wiki):
For example: If you set variable a in Python
a = 1.23
and write the following line in a markdown cell:
a is {{a}}
It will be displayed as:
a is 1.23
Further info on this functionality being integrated into ipython/jupyter is discussed in the issue trackers for ipython and jupyter.
The link: installing notebook extention
gives a clear description of what is necessary to enable the use of variables in markdown cells. Following it, performed the following actions to realize it:
conda install -c conda-forge jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
after a successful completion of the above command I enabled the python markup extension, from jupyter dashboard, as per the following illustration:
Last but not least!!! The NOTEBOOK HAS TO BE TRUSTED to make the markup extension works with python variables
and it worked for me!

Resources