ipywidgets

Execute algorithm step by step in Jupyter

牧云@^-^@ 提交于 2019-12-05 18:47:38
I am trying to show the execution of a Python program in Jupyter, step by step. For example, I can visualize the value of a variable in a program as in the following toy program: from IPython.display import display, clear_output from time import sleep def sum_first_integers(n): res = 0 for i in range(n+1): res += i clear_output(wait=True) display(res) sleep(.5) return res This shows the value of res at each step of the algorithm, and I added a sleep(.5) to be able to actually view the execution of the algorithm. My question is whether there exists a better way of performing this visualization:

How to display matplotlib plots in a Jupyter tab widget?

半城伤御伤魂 提交于 2019-12-05 17:56:58
I am having trouble displaying plots inside of Jupyter tab widgets. Consider the following snippet: import matplotlib.pyplot as plt import pandas as pd import ipywidgets as widgets import numpy as np out1 = widgets.Output() out2 = widgets.Output() data1 = pd.DataFrame(np.random.normal(size = 50)) data2 = pd.DataFrame(np.random.normal(size = 100)) with out1: fig1, axes1 = plt.subplots() data1.hist(ax = axes1) display(fig1) with out2: fig2, axes2 = plt.subplots() data2.hist(ax = axes2) display(fig2) tab = widgets.Tab(children = [out1, out2]) tab.set_title(0, 'First') tab.set_title(1, 'Second')

Interactive Timer in Jupyter Notebook

て烟熏妆下的殇ゞ 提交于 2019-12-04 10:30:43
I have a function which records data and takes a while to complete. While the data is being recorded, I would like to have a button which, upon being pressed, displays how much time has elapsed since the data acquisition has started. Is this possible to do in Jupyter? I'm having issues as the data acquisition blocks the widget from activating, and if I try and run the widget in the background, it doesn't receive the on_click event until the data acquisition has finished. On the other hand, if I send the data acquisition to the background, then data is lost once the background job finishes.

How to alight and place ipywidgets

 ̄綄美尐妖づ 提交于 2019-12-04 09:51:58
Is there a way to control the placement and alignment of ipywidgets (inside jupyter notebook)? from ipywidgets import widgets from IPython.display import Javascript, display event_type_ui = widgets.Text(value='open', description='Test Event') platform_ui = widgets.Text(value='Android', description='Control Event') display(event_type_ui) display(platform_ui) I would like to specify an offset (in pixels?) to allow the label to fit and to have two controls aligned vertically. After some fiddling, I was able to get this: Before: After: Here is a copy-paste snippet, if interested: from ipywidgets

Really confused with Jupyter Notebook, Lab, extensions, and ipywidgets

随声附和 提交于 2019-12-04 01:36:49
I want to create an interactive JupyterLab Notebook application, and I need to create a series of custom Widgets. So I started looking into this matter, and the more I look the more confused I become. To make things simple I will ask a bunch of simple questions: One of the most common ways to use widgets on Jupyter Notebooks is to use the ipywidgets library. Right? Unlike the classic Notebook, the Notebook of JupyterLab cannot render JavaScript directly. As a result, the tutorials about custom widget creation in the ipywidgets docs are impossible to run on JupyterLab. Right? If one wants to

How to get ipywidgets working in Jupyter Lab?

流过昼夜 提交于 2019-12-03 18:30:25
问题 In Jupyter Notebook, ipywidgets work fine, however they seem to not work in Jupyter Lab (which is supposedly better than Notebook). I followed these directions. Step 1: Installed Node.js (https://nodejs.org/en/) Step 2: Installed requirements on Python 3 with conda: conda install -c conda-forge ipywidgets jupyter labextension install @jupyter-widgets/jupyterlab-manager Unfortunately, basic widgets do not work inside the jupyter lab notebook: 回答1: JupyterLab now prefers a model where arbitrary

Using Ipython ipywidget to create a variable?

你。 提交于 2019-12-03 11:44:29
This seems really simple but I have not been able to find a single example or to solve this myself. How do I use an ipywidget widget to create or return a python variable/object, such as a list or string, that can be used in a following cell? harringr There is a good introduction to ipywidgets at http://blog.dominodatalab.com/interactive-dashboards-in-jupyter/ which answers this question. You need two widgets, one for input, and another to bind the value of that input. Here's an example for text input: from ipywidgets import widgets # Create text widget for output output_variable = widgets

Place ipywidgets into HTML into Jupyter notebook

心已入冬 提交于 2019-12-03 09:22:56
问题 With the following minimal example, I can create buttons which interact with the Jupyter notebook and an HTML table, which is displayed in the notebook. import ipywidgets from IPython.display import display from IPython.core.display import HTML def func(btn): print('Hi!') btn1 = ipywidgets.Button(description="Click me!") btn1.on_click(func) btn2 = ipywidgets.Button(description="Click me!") btn2.on_click(func) display(btn1) display(btn2) display(HTML( '<table>' + '<tr><td>Something here</td>

Return value from function where ipython widgets are used to obtain input parameters

淺唱寂寞╮ 提交于 2019-12-02 06:15:51
问题 I'm trying to "widgetize" my IPython notebooks and am running into trouble with events and returning values from a function. This is the workflow I'm thinking is the best way to go: using widgets to get the input values for an arbitrary function call the function on event trigger return value from function I first tried using the "interact" method to call the function, but that seemed difficult to associate events and return values. From reading other interactive examples, making a class

Jupyter: embed live interactive widgets

烈酒焚心 提交于 2019-11-30 18:20:46
According to the Jupyter blog here , it is now possible to embed interactive widgets in a static webpage: Live interactive widgets can now be embedded into static web pages or blogs by inserting an html snippet containing the serialized widget state. This also works with custom widget libraries. See http://jupyter.org/embed-jupyter-widgets.html . When I open the example above, in firefox or chrome, I get the interactive widgets alright! However, if I create a new notebook with the same bit of python code, save the notebook as html, and then copy-paste the embeddable HTML snippet to render the