I'd like to install and enable Table of Contents (2) plugin using command-line.
The docs suggest that I can do the following
jupyter nbextension enable <nbextension require path>
How do I find this path for this extension?
I'd like to install and enable Table of Contents (2) plugin using command-line.
The docs suggest that I can do the following
jupyter nbextension enable <nbextension require path>
How do I find this path for this extension?
It says https://www.npmjs.com/package/ijavascript
In Windows, Anaconda offers a convenient distribution to install Python and many other packages, such as Jupyter and IJavascript.
But it isn't explained how. Neither on Anaconda site (once Anaconda is already installed).
Update: I know about
npm install -g ijavascript ijsinstall
But then what's difference with Linux ? Because I got this error, I thought there was something specific on Windows.
Error running
jupyter --version
Error: Command failed: jupyter --version 'jupyter' is not recognized as an internal or external command, operable program or batch file.
It should probably say "such as Jupyter, where IJavascript can run", but just like the documentation says
Then
npm install -g ijavascript
Followed by
ijsinstall
You need to run jupyter
from the Anaconda prompt, or add Anaconda's executable binaries to your PATH
(which is an option during installation). As that error is directly from CMD, it has really nothing to do with Anaconda, Jupyter, or ijavascript directly, but rather you are missing some OS setup
Run ‘pip3 install jupyter‘ in the command shell.
Look through this site to get some help. Google and YouTube will be very good friends to get this set up.
I am creating certain heatmaps using gmaps which is a jupyter extension. The output of this library are interactive google maps like one here.
I want the final output to be a png image which should be obtainable via google static maps but I don't know how do I convert a map with an extra layer of heatmap to a static map programatically.
Is it possible to convert a map like this to a static image.
Thanks
If you need a heatmap, you can't solely relies on the static map api, you will either grab the tiles from using a Google Maps API for JavaScript and lay them out in your canvas or container or a backend service or use some other heatmap libraries to output the layer in the same projection that you use for Google Maps API (defaults to Web Mercator) as a PNG and overlay on top your static map image.
In a Jupyter notebook there are some built-in magics that change the contents of a notebook cell. For example, the %load
magic replaces the contents of the current cell with the contents of a file on the file system.
How can I write a custom magic command that does something similar?
What I have so far prints something to stdout
def tutorial_asset(line): print('hello world') def load_ipython_extension(ipython): ipython.register_magic_function(tutorial_asset, 'line')
And I can load it with %load_ext tutorial_asset
. But from there I'm lost.
[Edit]:
I've found a way to get to the interactive shell instance:
@magics_class class MyMagics(Magics): @line_magic def tutorial_asset(self, parameters): self.shell
The self.shell
object seems to give complete access to the set of cells in the notebook, but the only way I can find to modify the cells is to do self.shell.set_next_input('print("hello world")')
. This isn't sufficient because, in a Jupyter notebook, that input cell is skipped, and it doesn't overwrite the input cell, it instead creates a new input cell after it.
This would be fine, but if I run the notebook a second time, it creates another input cell with the same file loaded, which is annoying. Can I have it load only once, say, by checking if the contents are already in the next cell?
EDIT: After a little further digging, I found that the current build of notebook cannot do both.
Well, this is a little tricky... Looking at the IPython code, it looks like you need to use set_next_input
if you want to replace the cell, and run_cell
if you actually want to run some code. However, I can't get both to work at once - it looks like set_next_input
always wins.
Digging into the code, the web front-end supports optional clearing of the output on set_next_input
. However, the kernel doesn't yet support setting this flag (and so output will always be cleared as the default action). To do better will require a patch to ipykernel.
The best I therefore have is the following code, using jupyter notebook version 4.2.1:
from __future__ import print_function from IPython.core.magic import Magics, magics_class, line_magic @magics_class class MyMagics(Magics): @line_magic def lmagic(self, line): "Replace current line with new output" raw_code = 'print("Hello world!")' # Comment out this line if you actually want to run the code. self.shell.set_next_input('# %lmagic\n{}'.format(raw_code), replace=True) # Uncomment this line if you want to run the code instead. # self.shell.run_cell(raw_code, store_history=False) ip = get_ipython() ip.register_magics(MyMagics)
This gives you a magic command lmagic
that will either replace the current cell or run the raw_code
depending on which bit of the code you have commented out.
In the first cell of every iPython (Jupyter) notebook, I almost always type:
%matplotlib inline import matplotlib.pyplot as plt import numpy as np
Is there a way to make it so that this cell appears at the top of each new notebook I create by default?
For example, could I save a template .ipynb
file somewhere, which is copied by iPython when creating a new notebook?
(I found this question, but it seems to be more about css than default content in cells.)
I know it may not be what you're looking for (this example is not good for working on notebooks that need to be run in multiple environments, e.g. shared), but I put the following in a file called ipython_config.py
in my .ipython
folder.
c.InteractiveShellApp.exec_lines = ['%matplotlib inline', 'import numpy as np', 'import scipy.constants as c', 'import scipy.integrate as sci', 'from mpl_toolkits.mplot3d import Axes3D', 'import scipy.optimize as sco' ]
This runs before anything runs in any interactive console, including the jupyter notebook. If you want explicit boilerplating, I think that you will be disappointed (unless you want to build in the functionality for us ☺)