Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoexec-fragment ? #282

Closed
parmentelat opened this issue Aug 30, 2017 · 11 comments
Closed

autoexec-fragment ? #282

parmentelat opened this issue Aug 30, 2017 · 11 comments

Comments

@parmentelat
Copy link
Collaborator

Hi; mostly thinking aloud here, but..

Would it make sense to create a new fragment-type, for example 'autoexec-fragment', that would cause the cell to be executed when the fragment shows up ?

not sure it that makes sense to many people, but I have the feeling that in my case in particular, it would make the whole presenter's life a lot easier; It could in particular contribute smoothening issue #254, that is related in the sense that the only reason why I need to select a cell is so I can evaluate it.

well again, just a thought - thanks !

@damianavila
Copy link
Owner

In fact I have implemented something to solve #254 for the JupyterCon talk but I have to put it in a PR now.
It essentially auto selects the first cell of each slide.
Regardless of that... maybe we can use the tags availability to mark a fragment as one to be executed when it is shown. I would avoid to add more types of fragments if we can do that with metadata.

Btw, thanks for posting your ideas!

@parmentelat
Copy link
Collaborator Author

It's great to hear that you have a solution for #254 and I am eager to be able to use that :)

as for how concretely marking a fragment for auto-execution, as I said I wrote the first idea that came to mind:)
I don't clearly see however what you mean by 'tags availability', can you be more specific about how this would look like in the metadata ?

@damianavila
Copy link
Owner

I don't clearly see however what you mean by 'tags availability', can you be more specific about how this would look like in the metadata ?

I am talking about this: jupyter/notebook#2048.
We could potentially read an auto-execute tag from the cell metadata and trigger the execution after the fragment is shown... I think... but I need to think a little bit more about it.

@parmentelat
Copy link
Collaborator Author

OK, thanks for making this more clear

Is there an easy way for me to benefit from the patch you made for jupytercon ?
it'd really help :)

thanks !

@damianavila
Copy link
Owner

damianavila commented Sep 5, 2017

The workaround is the following:

Add this piece of code in main.js:

      // select the first cell from each slide
      setTimeout(function(){
        var current_cell_index = reveal_cell_index(Jupyter.notebook);
        console.log(current_cell_index);
        // select and focus on current cell
        Jupyter.notebook.select(current_cell_index)
      }, 500);

after lines:

https://github.com/damianavila/RISE/blob/master/rise/static/main.js#L347

and

https://github.com/damianavila/RISE/blob/master/rise/static/main.js#L353

That will select every first cell of each slide when you change the slides... if 500 ms is too much for you, you can probably diminish it (I tested with 200ms and seems to work OK).

Beware to hard clean the browser cache after making the change in main.js, so you have the latest code.

I need to put this with a proper config option and maybe add an option to link the action to a keyboard event if you only want this behavior in specific slides and not in all of them.

Hope it helps!

@parmentelat
Copy link
Collaborator Author

Hey; thanks for the tip
I am a little confused though, do the line numbers really apply to the master version ? the locations where that would point look odd at first sight and do not seem to make actual sense; the simplest maybe is to send me a full working file, I'll find my way from there..

Also, stupid question but: I have the system installed through pip + I have the git repo on a file; what's the easiest way to try the code in the git repo ? I feel like I did that already but can't remember how I did it, it feels like I used a very quick and dirty way, and I'd rather not do that again :)

thanks in advance -- I'm eager to try this out - Thierry

@damianavila
Copy link
Owner

Hey; thanks for the tip
I am a little confused though, do the line numbers really apply to the master version ? the locations where that would point look odd at first sight and do not seem to make actual sense; the simplest maybe is to send me a full working file, I'll find my way from there..

Sorry about that, I corrected the links above. You should see the correct locations now... I merged some pull request after giving this instructions for first time.

Also, stupid question

I would follow these instructions: https://github.com/damianavila/RISE#development, to try new things.

@parmentelat
Copy link
Collaborator Author

parmentelat commented Sep 6, 2017

ok, now the location for the patched makes more sense; about the devel. mode OTOH, I am struggling a bit:

  • first, I am on the mac; when running npm run reset-reveal it turns into running this
parmentelat ~/git/RISE $  npm run reset-reveal

> rise@0.5.0 reset-reveal /Users/parmentelat/git/RISE
> sed -i '11 s_^_/*_' rise/static/reveal.js/css/reveal.css

sed: -i may not be used with stdin
<snip>

turns out sed -i on the mac requires a suffix argument:

I would advocate invoking sed in a less fragile way, simply like this

sed -i.distrib '11 s_^_/*_' rise/static/reveal.js/css/reveal.css

which works on both mac and linux, as far as I can tell; let me know if you'd like me to create a PR to this effect - I'm not fluent with npm but it looks like a simple change in package.json ?


  • second, and more importantly for me, after following the guide - modulo this above that I triggered manually - I don't seem to use the version of main.js that I have in my writable git repo

from my rather shallow knowledge of npm and from the contents of package.json, I would tend to think that my manually invoking sed should have done the job of reset-reveal, which at first I thought I was not mimicking completely.

the way I test it is to just call console.log from main.js, I was expecting the message to show up upon loading of a notebook, or maybe upon entering RISE mode, but to no avail; so I'm unsure how to go from here...

I can find main.js in 2 locations that are:

  • in my git repo
  • and in the system area under
    /opt/local/Library/Frameworks/Python.framework/Versions/3.6/share/jupyter/nbextensions/rise/main.js

should I expect the former to be copied into the latter after I followed the instructions as per the devel guide ? because they're different in my case ?

PS. I ran all the devel. guide with a modified main.js, so I'm not yet talking about doing a change in the JavaScript file on the fly.

PS2. also I had to run everything under sudo, of course

PS3. Also I figured that running pip install -e . was not doing anything in my case because I had that same version installed in my system; so I did pip install --upgrade -e . instead, which apparently was doing more stuff; but to no avail either

PS4. also I cleared my browser cache

@damianavila
Copy link
Owner

which works on both mac and linux, as far as I can tell

I need to test it on Linux...

let me know if you'd like me to create a PR to this effect -

Yep, For sure!

I'm not fluent with npm but it looks like a simple change in package.json ?

Right.

should I expect the former to be copied into the latter after I followed the instructions as per the devel guide ? because they're different in my case ?

jupyter-nbextension install rise --py --sys-prefix --symlink command should symlink the js you have in the repo with the js in the specific nbextension folder under PREFIX/share/jupyter, but maybe that is not happening in you case... can you try with: jupyter-nbextension install rise --py --sys-prefix, that will copy stuff instead of symlinking...

PS. I ran all the devel. guide with a modified main.js, so I'm not yet talking about doing a change in the JavaScript file on the fly.

Probably the simlinking is not working... what is you jupyter --paths inside the environment where you have RISE installed in development mode?

PS2. also I had to run everything under sudo, of course

Why? In my case I am using conda... but you should not need to sudo things in the pip world... I think.

PS3. Also I figured that running pip install -e . was not doing anything in my case because I had that same version installed in my system; so I did pip install --upgrade -e . instead, which apparently was doing more stuff; but to no avail either

mmm... that is weird... so... are you using the same environment where you have the released version installed to do development?

PS4. also I cleared my browser cache

Nice to know, it is a source of problems with stale-cached js.

@parmentelat
Copy link
Collaborator Author

thanks a lot

I created the PR as #285

Removing --symlink did the job fine, I'm good :)

and yes, this is a single-user setup, and I tear down everything often enough to not worry too much about the installed stuff, so yes, I wanted this to go into the installed version as I plan to use it for real :)

My understanding is that whenever I change main.js, I'll need to rerun

sudo jupyter-nbextension install rise --py --sys-prefix

that's fine...

thanks again

@damianavila
Copy link
Owner

damianavila commented Sep 8, 2017

My understanding is that whenever I change main.js, I'll need to rerun
sudo jupyter-nbextension install rise --py --sys-prefix
that's fine...

Yep, it seems your solution for now. Thanks for battle this out. I will try to review your PR as soon as I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants