moble / jupyter_boilerplate Goto Github PK
View Code? Open in Web Editor NEWAdds a customizable menu item to Jupyter (IPython) notebooks to insert boilerplate snippets of code
License: MIT License
Adds a customizable menu item to Jupyter (IPython) notebooks to insert boilerplate snippets of code
License: MIT License
By editing the bottom of the custom.js file, I have succeeded in adding a three customized submenu items under the python snippet menu. I now want to promote one customized submenu (my_favorites2) up up to the level of a menu item next to the snippets menu item. I succeeded in doing so with the numpy sub-menu but not with my_favorites2. I am a javascript beginner.
snippets_menu.options['menus'] = snippets_menu.default_menus;
snippets_menu.options['menus'][0]['sub-menu'].push(horizontal_line);
snippets_menu.options['menus'][0]['sub-menu'].push(my_favorites);
snippets_menu.options['menus'][0]['sub-menu'].push(my_favorites2);
snippets_menu.options['menus'][0]['sub-menu'].push(my_favorites3);
snippets_menu.python.numpy['sub-menu-direction'] = 'left'; // Point new Numpy menus to left
//snippets_menu.python.my_favorites2['sub-menu-direction'] = 'left'; // Point new Numpy menus to left
//snippets_menu.options['menus'].push(snippets_menu.default_menus[0]); // Start with the remaining "Snippets" menu
snippets_menu.options['menus'].push(snippets_menu.python.numpy); // Follow that with a new Numpy menu
//snippets_menu.options['menus'].push(snippets_menu.python.my_favorites2); // Follow that with a new Numpy menu
console.log('Loaded `snippets_menu` customizations from `custom.js`');
Hello there,
I am trying to include a customised menu in jupyter notebooks using menu_snippets. Anyhow, when I put example code in the custom.js
, I do not get any additional menu after refreshing my jupyter notebooks.
custom.js
file such that I could see an additional menu in my toolbar.[W 12:54:30.919 NotebookApp] 404 GET /nbextensions/nbextensions_configurator/tree_tab/main.js?v=20230317125426 (127.0.0.1) 9.610000ms referer=http://localhost:8888/tree
I have tried different ways and also inspected the main.js
in jupyter_boilerplate, but could not find a way out of this. Do you have any ideas what I can do to make the custom.js
do its magic?
pip install jupyter
jupyter/nbextensions
existed when I executed 3.a, but I cannot verify how that happened anymore.cd $(jupyter --data-dir)/nbextensions
git clone https://github.com/moble/jupyter_boilerplate
jupyter nbextension install jupyter_boilerplate --user
jupyter nbextension enable jupyter_boilerplate/main --user
custom.js
in ~/.jupyter/custom/custom.js
and added the following code:require(["nbextensions/snippets_menu/main"], function (snippets_menu) {
console.log('Loading `snippets_menu` customizations from `custom.js`');
var horizontal_line = '---';
var my_favorites = {
'name' : 'My favorites',
'sub-menu' : [
{
'name' : 'Menu item text',
'snippet' : ['new_command(3.14)',],
},
{
'name' : 'Another menu item',
'snippet' : ['another_new_command(2.78)',],
},
],
};
snippets_menu.options['menus'] = snippets_menu.default_menus;
snippets_menu.options['menus'][0]['sub-menu'].push(horizontal_line);
snippets_menu.options['menus'][0]['sub-menu'].push(my_favorites);
console.log('Loaded `snippets_menu` customizations from `custom.js`');
});
5.19.0-35-generic #36~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Feb 17 15:17:25 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
custom.js
is neither in /snippets_menu
nor /jupyter_boilerplate
, I would think it would work regardless of my confusion.I would be grateful if you have a solution for that or have an idea on how to fix that issue.
Best
This is a new feature since the last time I was doing serious tree traversal. Might be useful...
Looks like EPath
stands for manipulating expressions by path. Perhaps meant to be a formation similar to XPath
. Ah, yes. It even says so in the docstring for epath
.
It would be great if a snippet could be targeted at specific locations in the code. For example, if the code to add imports could be directly sent to the first cell even if I am somewhere else in the code. Furthermore, if parts of the snippet can go in different places that would be even better. This will allow adding profiling to a notebook in which case you may wish to run something at the beginning of the notebook (say, start a data collection process) and run the analysis at the end of the notebook.
Like %tic
%toc
, install nbextension, etc.
There are still some "not yet implemented" functions, that are mostly just
placeholders to remind me to do something about them.
Generally, more boilerplate can always be added.
The main thing stopping this from being a pretty general menuing extension is the inability to accept general JavaScript for onclick instead of snippets.
While I'm at it, I might as well add an option to accept simple text items for typesetting -- for example, to explain that CODATA returns are val,unit,uncert
.
Change the default menu to specifically note that it is python. Then add (as
best I can) some boilerplate for Julia and R. Note that markdown is common to
all three, so I can just separate that out, and add it in to each.
E.g., "SymPy => Functions => Elementary Functions" shows a menu that goes from "Abs" to "Atan2", arrives to the screen's lower border and stops there: no cosine, no exponential, no...
I've followed the instructions in README but nothing happened.
Also there are two errors in console log on page load:
require.js?v=6da8be3…:1952 GET http://localhost:8888/nbextensions/jupyter_boilerplate-master.js?v=20161209231031
utils.js:50 Failed to load extension: ["nbextensions/jupyter_boilerplate-master"] Error: Script error for "nbextensions/jupyter_boilerplate-master"
When clicking on any documentation link it just open another tab with my notebook.
May be it is a template issue because the link has an empty href.
<li>
<a href="#" target="_blank" title="Opens in a new window">
<i class="fa fa-external-link menu-icon pull-right"></i><span>Documentation</span>
</a>
</li>
After checking "Snippets Menu" in Configurable nbextensions, Snippets did't appear as expected, then I checked out "JavaScript console", found a red line :".html(menu_item_spec.name)---Uncaught (in promise) TypeError: Cannot read property 'name' of undefined" at main.js(line 181) , while I don’t know much about JS, could you please help with it?
Thanks!
It would be so awesome if, in addition to being able to go to the snippets menu in order to insert snippet, one could simply type, for example,
function
then hit a hot key, say <tab>
and have the snippet inserted, like
def function_name(): variables = something return variables
I don't know how feasible this is, but it would be awesome. There is already something like this called ultisnips (https://github.com/SirVer/ultisnips) as a package for Vim.
Since I'm so new to JavaScript, I hadn't seen jQuery before, so some of my code is quite ugly. It still
works, but I could bring it more into line with other ipython programming. Something like the following:
var help_menu=$("body").find("ul#help_menu");
var boilerplate_menu=$("<ul/>").addClass("dropdown-submenu").append($(<a/>").text(sub_menu_item));
help_menu.after(boilerplate_menu);
It would be nice to add a couple improvements to the menu-item formatting. For
example, it should be possible (and easy!) to take an arbitrary javascript
function as the command to be executed onClick
.
Or maybe we want the top level of a sub-menu to be clickable -- for example,
where there's one basic option that might be needed frequently, but then a
sub-menu with some more advanced options. In this case, the item's value would
probably be an array, with first element a string, and second element the
sub-menu.
This one could probably be changed when I deal with the first issue above.
I'm new to javascript, so I based my menu structure on objects, not realizing
that they have no order. So it's impossible to re-order the menus. I
apparently should have used arrays. It should be easy enough to redo this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.