Coder Social home page Coder Social logo

Comments (5)

kh90909 avatar kh90909 commented on May 20, 2024 2

Also, here's a more functional example of updating an output widget from a button click callback, to show how this can be used to position output (e.g. a matplotlib plot) relative to other widgets:

%matplotlib inline

# To prevent automatic figure display when execution of the cell ends
%config InlineBackend.close_figures=False 

import matplotlib.pyplot as plt
import numpy as np

from IPython.html import widgets
from IPython.display import display,clear_output

plt.ioff()
ax=plt.gca()
plt.plot(np.random.randn(100),np.random.randn(100),'+')

out=widgets.Output()
button=widgets.Button(description='Next')
vbox=widgets.VBox(children=(out,button))
display(vbox)

def click(b):
    ax.lines[0].set_xdata(np.random.randn(100))
    ax.lines[0].set_ydata(np.random.randn(100))
    with out:
        clear_output(wait=True)
        display(ax.figure)

button.on_click(click)
click(None)

image

from ipywidgets.

kh90909 avatar kh90909 commented on May 20, 2024

The minimal test case above raises another potential issue, but I haven't convinced myself that this is not just an error on my part:

When the button is clicked, only blank space is added to the output widget. 'Hello world' is not printed.

from ipywidgets.

jdfreder avatar jdfreder commented on May 20, 2024

from IPython import get_ipython
to IPython/html/widgets/widget_output.py, but I'm not familiar enough with the code to be sure if this is the correct place to make that change, or if the fix should be further upstream.

That's right, get_ipython() used to be available globally, looks like that's no longer the case after the big split.

Thanks for the excellent example of how a plot can be relocated! Feel free to open a PR to add that to the examples folder.

The minimal test case above raises another potential issue, but I haven't convinced myself that this is not just an error on my part:

When the button is clicked, only blank space is added to the output widget. 'Hello world' is not printed.

I wasn't able to reproduce this, it may be fixed in master.

from ipywidgets.

minrk avatar minrk commented on May 20, 2024

That's right, get_ipython() used to be available globally, looks like that's no longer the case after the big split.

Since the bug report is using IPython prior to the split, I don't think that's the case. The issue is that we inject get_ipython into globals only while interactive user code is running. Comm messages may not be handled in that context (arguable whether they should be). In general, though, no library code should rely on get_ipython in globals, and always import it. Only interactively typed code should access it via globals.

from ipywidgets.

jdfreder avatar jdfreder commented on May 20, 2024

Thanks for clarifying @minrk

from ipywidgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.