Run Jupiter Notebook Interact inside a Tab widget
See original GitHub issueI would like to have an interact function/widget inside a tab. For example, once the user activates a particular checkbox, other widgets will appear in that Tab. This is an example of what I have done so far:
import ipywidgets as widgets
def initial_condition(Turn_on_IC):
# this is the function that "generates" the initial condition
# text-boxes if the user turns on the IC checkbox
if Turn_on_IC == True:
label_iniCond = widgets.HTML("""The Initial elevation file dictates the
dry/wet zones of the bathymetry. The initial U and V velocity files specifies
the velocities in the x and y directions. They must be uploaded in
the Jupyter Notebook Home folder before running the simulation.""",
layout = widgets.Layout(height = '45px', width = '90%',
size = '20'))
space_box = widgets.Box(layout=widgets.Layout(height ='25px', width='90%'))
# this ^ box is created to have space among widgets
# initial elevation widget container (label and textbox)
label_iniElev = widgets.Label('Initial Elevation Text File:',
layout = widgets.Layout(width = '18%'))
iniElev_text = widgets.Text(layout=widgets.Layout(width = "50%",height = '85px'))
container_iniElev = widgets.HBox(children=[label_iniElev,iniElev_text])
# initial u vel widget container (label and textbox)
label_Uvel = widgets.Label('Initial U Velocity Text File:',
layout = widgets.Layout(width = '18%'))
Uvel_text = widgets.Text(layout = iniElev_text.layout)
container_Uvel = widgets.HBox(children=[label_Uvel,Uvel_text])
# initial v vel widget container (label and textbox)
label_Vvel = widgets.Label('Initial V Velocity Text File:',
layout = widgets.Layout(width = '18%'))
Vvel_text = widgets.Text(layout = iniElev_text.layout)
container_Vvel = widgets.HBox(children=[label_Vvel,Vvel_text])
iniCond_box = widgets.VBox(children=[label_iniCond,space_box,container_iniElev,
container_Uvel,container_Vvel])
return(iniCond_box)
else:
iniCond_box = widgets.VBox(children=[])
return(iniCond_box)
iniCond = interact(initial_condition, Turn_on_IC=False)
I’m calling the function with interact and the function works well if you run it like this…but as soon as I add it to a tab, it doesn’t. It displays this error message: ValueError: Can’t clean for JSON: <function initial_condition at 0x114f23268>
Also, if I use interactive instead of interact the checkbox appears in the tab, but the function does not work. I’ve ran out of ideas, does anyone know how could I solve this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Jupyter ipywidget: use one slider widget in one specifc tab in ...
The Interact classes are similarly named but have different functions. ... out2 = widgets.interactive(hist2, size1=size1) tab = widgets.
Read more >Interactive Controls in Jupyter Notebooks | by Will Koehrsen
In this article, we'll see how to get started with IPython widgets ( ipywidgets ), interactive controls you can build with one line...
Read more >3.3. Mastering widgets in the Jupyter Notebook
The @interact decorator shows a widget for controlling the arguments of a function. Here, the function f() accepts an integer as an argument....
Read more >Using interactive with a Tab widget - Jupyter Community Forum
I created a Tab widget which contains different ToggleButtons widgets, representing different sub-options for the option defined by the tab.
Read more >Jupyter Interactive Widget Ecosystem Tutorial | SciPy 2020
Jupyter widgets are powerful tools for building user interfaces with graphical controls such as sliders and text boxes inside a Jupyter ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks a lot for answering so fast! I’m sorry for not explaining myself better. I’m creating a GUI capable of generating a simple bathymetry, an input file and finally run and post process a wave model. So each tab would be a step of that procedure. I’ve attached an image of my GUI so far. The example I gave before belongs to the “Initial condition” tab seen in the image. Once the user press the checkbox, the input file will have a ‘true’ (hence why that option can’t be a accordion) on the option of uploading initial conditions. I would like for the text-boxes to appear if the user presses the checkbox to limit what the user would input to the input file. If he doesn’t want to add initial conditions, then he shouldn’t have the possibility to write/edit anything else in that part. The second option you gave is more similar to what I’m working with, but it still does not appear inside a tab. Hopefully now that I’ve explained the issue better, you could help 😃 Thanks in advance!
Great!