These are chat archives for ipython/ipython

3rd
Dec 2015
Jonathan Frederic
@jdfreder
Dec 03 2015 01:40
@AaronWatters although the internal implementation is less than ideal, you should be able to do this using the OutputWidget.
Charles Prado
@chr0x
Dec 03 2015 12:25
/who
Andreas Klostermann
@akloster
Dec 03 2015 14:29
@minkrk, yes I meant nbpresent, thank you!
Andreas Klostermann
@akloster
Dec 03 2015 15:03
@jasongrout I think it's possible if you display the widgets and output explicitly with display methods
I have an example of an interactive bokeh plot inside a widget here: https://github.com/akloster/bokeh-snake
silly example though
Jason Grout
@jasongrout
Dec 03 2015 16:55
@akloster - I forgot about @jdfreder's output widget. With that, you can embed output in the widget area. I think you can't get a widget to show up in the output area, though.
Nicholas Bollweg
@bollwyvl
Dec 03 2015 17:45
@jasongrout is nbbrowserpdf ready for production deployment?
Probably not. It does not have tests, as I haven't picked out how best to test my browser in my server in my browser on my server
I think I may have to in fact dump it to PNGs and image diff those
Nicholas Bollweg
@bollwyvl
Dec 03 2015 18:22
Anaconda-Server/nbbrowserpdf#4
epifanio
@epifanio
Dec 03 2015 19:33
Hi, is in ipywidget a way to have a slider with a custom range of values like : 90:-90:90 ? so that the center slider is -90 and the left and right ends are 90.
like the left side of the slider range should be: reversed(range(-90, 90)) and the right end: range(-90, 90)
Jason Grout
@jasongrout
Dec 03 2015 19:41
That's not available now. It's related to our discussion over on ipython/ipywidgets#259. It would be great to have a slider that had arbitrary values linked to the slider positions
well, you can do it by managing the transformation yourself, and not displaying the readout (so the user isn't confused)
epifanio
@epifanio
Dec 03 2015 19:42
like use a normalized range 0-1 in the slider range and then apply a transformation (rescaling) based on my needs ?
make sense, how to hede the slider output ?
*hide
that’s how i’m creating the widget: https://gist.github.com/0d4f521bad1dcd81e56e
Jason Grout
@jasongrout
Dec 03 2015 19:45
right, or you can make an int slider with range 0-181
you can set the readout to false
Sylvain Corlay
@SylvainCorlay
Dec 03 2015 19:46
A slider with arbitrary values would probably have to be a Selection widget like the dropdown...
Jason Grout
@jasongrout
Dec 03 2015 19:46
oh, it won't work with @interact. You'll need to create your slider manually
Sylvain Corlay
@SylvainCorlay
Dec 03 2015 19:47
Another feature is the ability to set the number of points rather than the steps.
Jason Grout
@jasongrout
Dec 03 2015 19:48
@SylvainCorlay - yeah, I could see a SelectionSlider or something
epifanio
@epifanio
Dec 03 2015 19:53
so i can’t use the shortcut, I was studing this https://github.com/rossant/euroscipy2014
trying to port it to jupyter 4.*
Jason Grout
@jasongrout
Dec 03 2015 19:54
what example were you trying to port?
epifanio
@epifanio
Dec 03 2015 19:55

all of them and make a pr, i’m done with the second and third notebooks. but the first one at last cell:

interact(complex_plot,
         title='my function',
         xscale=(.1, 100.),
         fun=widgets.RadioButtons(values=['sin', 'cos', 'arctan']),
         dashed=widgets.ToggleButton(),);

gave me:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-c4e8b9063d86> in complex_plot(fun, title, dashed, xscale)
      9                  xscale=5.):
     10 
---> 11     f = getattr(np, fun)
     12     t = np.linspace(-xscale, +xscale, 1000)
     13     s = '--' if dashed else '-'

TypeError: getattr(): attribute name must be string
In [9]
epifanio
@epifanio
Dec 03 2015 20:02
actually the second notebook also fail in building a radio button for the kernel_control i managed to convert the other changes like HBox, VBox, set_css etc. I can post the dice/error later if we can have fixed the first notebook. Once done with the tutorial i’ll try to apply what i learnd to my use case for the custom slider
Jason Grout
@jasongrout
Dec 03 2015 20:33
can you print out fun just before the getattr call?
what is it getting?
epifanio
@epifanio
Dec 03 2015 20:52
@jasongrout , back on line. sorry for delay

i added print(fun) in:

def complex_plot(fun='sin', 
                 title='sine', 
                 dashed=False, 
                 xscale=5.):
    print(fun)
    f = getattr(np, fun)
    t = np.linspace(-xscale, +xscale, 1000)
    s = '--' if dashed else '-'

    plt.plot(t, f(t), s, lw=3);
    plt.xlim(-xscale, +xscale);
    plt.title(title);

it is just a string

print(fun)
print(type(fun))
returns:

sin
<class 'str’>
Jason Grout
@jasongrout
Dec 03 2015 20:54
how about a try/except around f=... to try to catch the exception and inspect the 'fun' value when there is an error
Jason Grout
@jasongrout
Dec 03 2015 20:56
or maybe even better, if you're familiar with pdb, do %pdb in a cell to turn on the debugger
epifanio
@epifanio
Dec 03 2015 20:57
I’m not familiar with pdb but i can give it a try
Jason Grout
@jasongrout
Dec 03 2015 20:58
clearly fun is not a string at some point - just trying to figure out what it is
epifanio
@epifanio
Dec 03 2015 20:59
i think in the cell with:
interact(complex_plot,
         title='my function',
         xscale=(.1, 100.),
         fun=widgets.RadioButtons(values=['sin', 'cos', 'arctan']),
         dashed=widgets.ToggleButton(),);
the windget that is rendered looks like:
Screen Shot 2015-12-03 at 3.59.40 PM.png
you can see the “drop down” menu where the user is supposed to chose the entry for the function type, is not rencdered
fun=widgets.RadioButtons(values=['sin', 'cos', 'arctan']),
Jason Grout
@jasongrout
Dec 03 2015 21:02
Yes, good call
can you construct a radiobuttons widget separately?
are there any javascript errors?
epifanio
@epifanio
Dec 03 2015 21:03
i’ll clear and restart and rerun with js debug on
epifanio
@epifanio
Dec 03 2015 21:05
you rock! it works fine with the right parameter.
Jason Grout
@jasongrout
Dec 03 2015 21:06
widgets.RadioButtons(values=[(name, getattr(np,name)) for name in ('sin', 'cos', 'arctan')])
then you don't need the getattr step, since you did it when you set up the control
epifanio
@epifanio
Dec 03 2015 21:10
the same issue for the notebook 2, fixing the wrong arguments it works fine now
epifanio
@epifanio
Dec 03 2015 21:19

notebooks:1,2,4 are working properly now. I’ve a doubt for notebook 3 it doesn’t print any error but seems to me at code cell number 4 it is supposed to render a widget, but there is no outupt. Starting the notebook with js debug on the cell with %javascript code is giving an error in the console:

Uncaught TypeError: Cannot read property 'extend' of undefined(anonymous function) @ VM1293:5context.execCb @ require.js:1678Module.check @ require.js:878Module.enable @ require.js:1165Module.init @ require.js:783(anonymous function) @ require.js:1441

the error when executing code cell 4 is notebooks is:

Couldn't create a view for model id 'd216d1e918124fe6a65fa869cab3b2c8'  --  Error: Class NumberSelector not found in registry (…)(anonymous function) @ main.min.js:12842
main.min.js:12842 Could not create view  --  WrappedError {stack: "Error: Couldn't create a view for model id 'd216d1…in.js?v=83565b60431aadd23c691d6878ddcb69:12840:33", message: "Couldn't create a view for model id 'd216d1e918124fe6a65fa869cab3b2c8'", error_stack: Array[3]}(anonymous function) @ main.min.js:12842
main.min.js:12842 Could not display model  --  WrappedError {stack: "Error: Could not create view↵    at new Error (nat…in.js?v=83565b60431aadd23c691d6878ddcb69:12840:33", message: "Could not create view", error_stack: Array[4]}(anonymous function) @ main.min.js:12842
03_custom.ipynb:1 Uncaught (in promise) WrappedError {stack: "Error: Couldn't create a view for model id 'd216d1…in.js?v=83565b60431aadd23c691d6878ddcb69:12840:33", message: "Couldn't create a view for model id 'd216d1e918124fe6a65fa869cab3b2c8'", error_stack: Array[4]}
03_custom.ipynb:1 Uncaught (in promise) WrappedError {stack: "Error: Could not display model↵    at new Error (n…in.js?v=83565b60431aadd23c691d6878ddcb69:12840:33", message: "Could not display model", error_stack: Array[4]}
main.min.js:12842 Couldn't process update msg for model id 'd216d1e918124fe6a65fa869cab3b2c8'  --  WrappedError {stack: "Error: Couldn't create a view for model id 'd216d1…in.js?v=83565b60431aadd23c691d6878ddcb69:12840:33", message: "Couldn't create a view for model id 'd216d1e918124fe6a65fa869cab3b2c8'", error_stack: Array[5]}(anonymous function) @ main.min.js:12842
main.min.js:12842 Couldn't resolve state request promise  --  WrappedError {stack: "Error: Couldn't process update msg for model id 'd…in.js?v=83565b60431aadd23c691d6878ddcb69:12840:33", message: "Couldn't process update msg for model id 'd216d1e918124fe6a65fa869cab3b2c8'", error_stack: Array[6]}(anonymous function) @ main.min.js:12842
03_custom.ipynb:1 Uncaught (in promise) WrappedError {stack: "Error: Couldn't resolve state request promise↵    …in.js?v=83565b60431aadd23c691d6878ddcb69:12840:33", message: "Couldn't resolve state request promise", error_stack: Array[6]}

the notebook is:
https://gist.github.com/epifanio/a1d81a6b46badff7b126

i think the bad behavior is related to the %javascript cell