Coder Social home page Coder Social logo

xwidgets's Introduction

xwidgets

Azure Pipelines Appveyor Documentation Binder Join the Gitter Chat

A C++ backend for Jupyter interactive widgets.

Introduction

xwidgets is a C++ implementation of the Jupyter interactive widgets protocol. The Python reference implementation is available in the ipywidgets project.

xwidgets enables the use of the Jupyter interactive widgets in the C++ notebook, powered by the xeus-cling kernel and the cling C++ interpreter from CERN. xwidgets can also be used to create applications making use of the Jupyter interactive widgets without the C++ kernel per se.

Usage

Launch the jupyter notebook with jupyter notebook and launch a new C++ notebook by selecting the xeus C++14 kernel in the new dropdown.

Widgets

Installation

We provide a package for the mamba (or conda) package manager.

  • Installing xwidgets and the C++ kernel
mamba install xeus-cling xwidgets -c conda-forge

Then, the front-end extension must be installed for either the classic notebook or JupyterLab.

  • Installing the extension for the classic notebook
mamba install widgetsnbextension -c conda-forge

Installation from sources

Or you can directly install it from the sources if you have all the dependencies already installed:

cmake -D CMAKE_INSTALL_PREFIX=your_install_prefix
make install

Trying it online

To try out xwidgets interactively in your web browser, just click on the binder link:

Binder

Documentation

To get started with using xwidgets, check out the full documentation

http://xwidgets.readthedocs.io/

Dependencies

All the dependencies of xwidgets are available for the mamba (or conda) package manager.

xwidgets jupyterlab_widgets widgetsnbextension xtl xproperty xeus nlohmann_json
master ^3.0.0 ^4.0.0 >=0.7,<0.8 >=0.11.0,<0.12 >=3.2,<4.0 >=3.9.1,<3.10
0.28.1 ^3.0.0 ^4.0.0 >=0.7,<0.8 >=0.11.0,<0.12 >=3.2,<4.0 >=3.9.1,<3.10
0.28.0 ^3.0.0 ^4.0.0 >=0.7,<0.8 >=0.11.0,<0.12 >=3.0,<4.0 >=3.9.1,<3.10
0.27.3 ^3.0.0 >=0.7,<0.8 >=0.11.0,<0.12 >=3.0,<4.0 >=3.9.1,<3.10
0.27.2 ^3.0.0 >=0.7,<0.8 >=0.11.0,<0.12 >=3.0,<4.0 >=3.9.1,<3.10
0.27.1 ^3.0.0 >=0.7,<0.8 >=0.11.0,<0.12 >=3.0,<4.0 >=3.9.1,<3.10
0.27.0 ^3.0.0 >=0.7,<0.8 >=0.11.0,<0.12 >=3.0,<4.0 >=3.9.1,<3.10
0.26.1 ^3.0.0 >=0.7,<0.8 >=0.11.0,<0.12 >=2.0,<3.0 >=3.9.1,<3.10
0.26.0 ^3.0.0 >=0.7,<0.8 >=0.11.0,<0.12 >=2.0,<3.0 >=3.9.1,<3.10
0.25.0 ^3.0.0 >=0.7,<0.8 >=0.11.0,<0.12 >=1.0,<2.0 >=3.6.1,<4.0

Packages jupyterlab_widgets and widgetsnbextension are not dependencies per se, but hold the frontend counterparts for JupyterLab and the classic notebook respectively that must be installed in the environment of the Jupyter server.

License

We use a shared copyright model that enables all contributors to maintain the copyright on their contributions.

This software is licensed under the BSD-3-Clause license. See the LICENSE file for details.

xwidgets's People

Contributors

antoineprv avatar ax3l avatar cmarmo avatar derthorsten avatar gouarin avatar joequant avatar johanmabille avatar martinrenou avatar rapgenic avatar sylvaincorlay avatar wolfv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xwidgets's Issues

Propagate dependency on xproperty

The cmake pacakge of xwidgets should propagate the dependency on xproperty so that downstream packages don't need to run find_package(xproperty) in their cmake.

Add static build

As with xeus, it would be nice to have the possibility to link to a static target (e.g. xwidget-static) given that the library is not available in many distros

x-tensibility to non-xeus kernels?

In order to drive wider/quicker adoption by existing kernels (without having to re-impl an existing kernel), it would seem reasonable to do one of:

  1. mock a xeus kernel so that an existing kernel can port out to xwidgets
  2. make (perhaps in xtransport?) xwidgets more flexible so that mimebundles can be got directly

Using xwidgets outside of Xeus

Chatted with some of you folks at JupyterCon about using xwidgets to add widget support to languages that can make calls to C libraries (using FFI, for example). Everyone seemed to think that would be fairly straightforward.

I've been playing with idea, but it looks like the widget comms are tied specifically to the xeus kernel in xtransport.hpp. Is it possible to abstract the comms layer in such a way that any kernel could use a widget by supplying their ZMQ connection information directly?

Diamond inheritance

We should have

xslider   ->  xnumber ->   xobject
          ->  xwidget ->   same xobject

Instead, to avoid dealing with diamonds for now, we have

xslider -> xnumber -> xwidget -> xobject

while xnumber should not inherit from xwidget in the general case.

Binary messages

The implementation of custom serialization with binary buffers cannot be done in the same way as in python, since the xjson representation does not carry types that may not be json serializable.

xholder and rvalue override of get()

in xholder, value() should be an lvalue or an rvalue depending on whether the holder is an lvalue or an rvalue, but only in the case of an owning holder.

XOBSERVE with xdisplay and xguid not updating

Hello all,

I'm trying to use a slider so I can skim through some images I have. However, it appears that if I use

xcpp::display(img,id, active);

in XOBSERVE the display is not updated. I'm happy to dump my unit test here, but I put it in github, as well as on mybinder.

Expected outcome: Move the slider, and xcpp::display will display an image. Move the slider past 50, and a different image will replace the previous image in the same position as before.
Actual outcome: The image never changes.

What am I doing wrong here?

Cheers,
Mark

Missing widget: Date picker

The date picker should probably hold the same date type that we will eventually adopt for xtensor and xframe date types...

Since numpy has date types with different precisions, maybe we could have this too...

In terms of internal representation, a statically allocated string might be the way to go.

macOS include error

When including the xwidgets header on macOS (10.14.6), the following error occurs:

#include "xwidgets/xslider.hpp"

error

In file included from input_line_7:1:
In file included from /Users/.../anaconda/install/envs/data_analysis/include/xwidgets/xslider.hpp:14:
In file included from /Users/.../anaconda/install/envs/data_analysis/include/xtl/xoptional.hpp:21:
In file included from /Users/.../anaconda/install/envs/data_analysis/include/xtl/xoptional_meta.hpp:15:
/Users/.../anaconda/install/envs/data_analysis/include/xtl/xmasked_value_meta.hpp:37:40: error: no template named 'enable_if_t' in namespace 'std'; did you mean 'enable_if'?
    using disable_xmasked_value = std::enable_if_t<!is_xmasked_value<E>::value, R>;
                                  ~~~~~^~~~~~~~~~~
                                       enable_if
/Users/.../anaconda/install/envs/data_analysis/include/c++/v1/type_traits:420:63: note: 'enable_if' declared here
template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {};

A similar errors occurs with xplot.

xwidgets were installed according to the README.md using conda and initialized for the jupyter notebook.

getting compile segfault with gcc 10.1.1

'''
/usr/bin/c++ -DGUID_LIBUUID -DXWIDGETS_EXPORTS -Dxwidgets_EXPORTS -I/home/joe/rpmbuild/BUILD/xwidgets-0.20.1/include -O2 -g -pipe -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -fasynchronous-unwind-tables -O3 -DNDEBUG -fPIC -Wunused-parameter -Wextra -Wreorder -march=native -flto -o CMakeFiles/xwidgets.dir/src/xbutton.cpp.o -c /home/joe/rpmbuild/BUILD/xwidgets-0.20.1/src/xbutton.cpp
'''

''''
/home/joe/rpmbuild/BUILD/xwidgets-0.20.1/include/xwidgets/xbutton.hpp: In instantiation of 'xw::xbutton::xbutton() [with D = xw::xmaterializexw::xbutton]':
/home/joe/rpmbuild/BUILD/xwidgets-0.20.1/include/xwidgets/xmaterialize.hpp:71:45: required from 'xw::xmaterialize<B, P>::xmaterialize(bool, A&& ...) [with A = {}; B = xw::xbutton; P = {}]'
/home/joe/rpmbuild/BUILD/xwidgets-0.20.1/include/xwidgets/xmaterialize.hpp:63:54: required from 'xw::xmaterialize<B, P>::xmaterialize(A&& ...) [with A = {}; B = xw::xbutton; P = {}]'
/home/joe/rpmbuild/BUILD/xwidgets-0.20.1/src/xbutton.cpp:16:50: required from here
/home/joe/rpmbuild/BUILD/xwidgets-0.20.1/include/xwidgets/xeither.hpp:20:54: internal compiler error: Segmentation fault
20 | static const std::unordered_setstd::string options({VA_ARGS});
| ^~~~~~~
/home/joe/rpmbuild/BUILD/xwidgets-0.20.1/include/xwidgets/xbutton.hpp:82:64: note: in expansion of macro 'XEITHER'
82 | XPROPERTY(std::string, derived_type, button_style, "", XEITHER("primary", "success", "info", "warning", "danger", ""));
| ^~~~~~~
Please submit a full bug report,
with preprocessed source if appropriate.
See https://bugs.mageia.org/ for instruction
'''

Move and copy semantics for final widgets

Final widgets are the ones that are directly instantiated by the user. Other types are CRTP bases that are not meant to be directly instantiated. Final widgets are generally explicitly marked as final in the code.

Besides the CRTP, they also differ from non-final widgets in that they are the ones calling open() and sending the initial state to the front-end. This cannot be done in the constructors of the bases because some properties would not have been initialized.

Hence, the first message containing the widgets state is sent in the end of the constructor of the final class.

At the moment, all the default constructors contain (besides the call to open) is the setting of the default values for the properties. If we manage to complete the setting of defaults in xproperty, one means to guarantee that open() is called last is to make it called by the m_comm constructor, and move the comm from the base xobject to all the final class as the last attribute.

A benefit of doing this (and implementing full RAII in xcomm) is that this would come for free for all other constructors (copy, move)...

xwidgets package doesn't come with Docker image

I am using the existing xeus-cling docker image to containerize a c++ project I have in a jupyter notebook. The only problem is, I was hoping on using the xwidgets package in this project, but the docker image does not come with the xwidgets package pre installed. It also doesn't come with a standard ubuntu or conda package manager, is there a clean way to get the xwidgets package in the docker image?

[question] API Status

I have run into the same issue twice with xplot I was wondering why the API had changed and what the status was, I have a similar issue with xwidgets where it downgrades all my packages, but I am able to build it from source.

Thanks

  • Chris

Getting realtime update of xwidget events

Hi,

I was trying to get the realtime value of the slider movement.
I was able to get it using xobserve.

xw::slider<double> slider;
slider.display()
XOBSERVE(slider, value, [](const auto& s) {
std::cout << "Observer: New Slider value: " << s.value << std::endl;
});

But when I try to use the slider value in another cell, it is not running simultaneously.
I also tried using capture variable.

Any Idea to get the slider value update simultaneously in a loop running in another cell?

Thanks,
Sreevishnu

Missing widgets

The following widgets are available in IPywidgets, but not in XWdigets.
A test is added to track missing widgets in #250

  • ColorsInputModel
  • ComboboxModel
  • DatePickerModel
  • DatetimeModel
  • FileUploadModel
  • FloatLogSliderModel
  • FloatRangeSliderModel
  • FloatsInputModel
  • GridBoxModel
  • HTMLMathModel
  • HTMLMathStyleModel
  • IntRangeSliderModel
  • IntsInputModel
  • NaiveDatetimeModel
  • StackModel
  • TagsInputModel
  • TimeModel

Jupyer Lab prints to the log

Problem

When I try to run the Button Widget section of the example in Jupyter Lab, the output of foo() is printed to the log.

xwidgts_log
(Kernel C++14)

Environment

I have installed xeus-cling and xwidgets via conda:

conda create -n xwidgets python=3.7
conda activate xwidgets
conda install xeus-cling xwidgets -c conda-forge
conda install -c conda-forge jupyterlab
conda install -c conda-forge nodejs
jupyter labextension install @jupyter-widgets/jupyterlab-manager

conda list

# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main  
attrs                     19.3.0                     py_0    conda-forge
backcall                  0.1.0                      py_0    conda-forge
binutils_impl_linux-64    2.33.1               he1b5a44_7    conda-forge
binutils_linux-64         2.33.1              h9595d00_17    conda-forge
bleach                    3.1.3              pyh8c360ce_0    conda-forge
ca-certificates           2019.11.28           hecc5488_0    conda-forge
certifi                   2019.11.28       py37hc8dfbb8_1    conda-forge
clang_variant             1.0                  cling_v0.6    conda-forge
clangdev                  5.0.0             hb222dda_1006    conda-forge
cling                     0.6                  he513fc3_2    conda-forge
cppzmq                    4.3.0             hc9558a2_1001    conda-forge
decorator                 4.4.2                      py_0    conda-forge
defusedxml                0.6.0                      py_0    conda-forge
entrypoints               0.3             py37hc8dfbb8_1001    conda-forge
gcc_impl_linux-64         7.3.0                habb00fd_1  
gcc_linux-64              7.3.0               h553295d_17    conda-forge
gxx_impl_linux-64         7.3.0                hdf63c60_1  
gxx_linux-64              7.3.0               h553295d_17    conda-forge
icu                       64.2                 he1b5a44_1    conda-forge
importlib-metadata        1.5.2            py37hc8dfbb8_0    conda-forge
importlib_metadata        1.5.2                         0    conda-forge
ipykernel                 5.2.0            py37h43977f1_0    conda-forge
ipython                   7.13.0           py37hc8dfbb8_2    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
jedi                      0.16.0           py37hc8dfbb8_1    conda-forge
jinja2                    2.11.1                     py_0    conda-forge
json5                     0.9.0                      py_0    conda-forge
jsonschema                3.2.0            py37hc8dfbb8_1    conda-forge
jupyter_client            6.1.1                      py_0    conda-forge
jupyter_core              4.6.3            py37hc8dfbb8_1    conda-forge
jupyterlab                2.0.1                      py_0    conda-forge
jupyterlab_server         1.0.7                      py_0    conda-forge
ld_impl_linux-64          2.33.1               h53a641e_7  
libedit                   3.1.20181209         hc058e9b_0  
libffi                    3.2.1                hd88cf55_4  
libgcc-ng                 9.1.0                hdf63c60_0  
libsodium                 1.0.17               h516909a_0    conda-forge
libstdcxx-ng              9.1.0                hdf63c60_0  
libuuid                   2.32.1            h14c3975_1000    conda-forge
libuv                     1.34.0               h516909a_0    conda-forge
markupsafe                1.1.1            py37h8f50634_1    conda-forge
mistune                   0.8.4           py37h516909a_1000    conda-forge
nbconvert                 5.6.1                    py37_0    conda-forge
nbformat                  5.0.4                      py_0    conda-forge
ncurses                   6.2                  he6710b0_0  
nlohmann_json             3.7.3                he1b5a44_1    conda-forge
nodejs                    13.10.1              hf5d1a2b_0    conda-forge
notebook                  6.0.3                    py37_0    conda-forge
openssl                   1.1.1e               h516909a_0    conda-forge
pandoc                    2.9.2                         0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
parso                     0.6.2                      py_0    conda-forge
pexpect                   4.8.0            py37hc8dfbb8_1    conda-forge
pickleshare               0.7.5           py37hc8dfbb8_1001    conda-forge
pip                       20.0.2                   py37_1  
prometheus_client         0.7.1                      py_0    conda-forge
prompt-toolkit            3.0.4                      py_0    conda-forge
ptyprocess                0.6.0                   py_1001    conda-forge
pugixml                   1.10                 he1b5a44_1    conda-forge
pygments                  2.6.1                      py_0    conda-forge
pyrsistent                0.16.0           py37h8f50634_0    conda-forge
python                    3.7.7           h191fe78_0_cpython  
python-dateutil           2.8.1                      py_0    conda-forge
python_abi                3.7                     1_cp37m    conda-forge
pyzmq                     19.0.0           py37hac76be4_1    conda-forge
readline                  7.0                  h7b6447c_5  
send2trash                1.5.0                      py_0    conda-forge
setuptools                46.1.1                   py37_0  
six                       1.14.0                     py_1    conda-forge
sqlite                    3.31.1               h7b6447c_0  
terminado                 0.8.3            py37hc8dfbb8_1    conda-forge
testpath                  0.4.4                      py_0    conda-forge
tk                        8.6.8                hbc83047_0  
tornado                   6.0.4            py37h8f50634_1    conda-forge
traitlets                 4.3.3            py37hc8dfbb8_1    conda-forge
wcwidth                   0.1.8              pyh9f0ad1d_1    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.34.2                   py37_0  
xeus                      0.23.5               h4d8c418_0    conda-forge
xeus-cling                0.8.1                he513fc3_2    conda-forge
xproperty                 0.10.1               hc9558a2_0    conda-forge
xtl                       0.6.13               hc9558a2_0    conda-forge
xwidgets                  0.20.0               hc9558a2_0    conda-forge
xz                        5.2.4                h14c3975_4  
zeromq                    4.3.2                he1b5a44_2    conda-forge
zipp                      3.1.0                      py_0    conda-forge
zlib                      1.2.11               h7b6447c_3  

On dealing with shared holders

The situation where we need shared holders occurs when a function needs to return a complex compound widget that reuses some widget in multiple cases (no clear ownership).

In most cases, users of xwidgets don't need to know about holders. It should probably not be the case either for shared holders.

This is a bit too verbose:

auto box_of_buttons() {
    auto b1 = xw::button_generator()
        .description("button 1")
        .finalize();
    auto b2 = xw::button_generator()
        .description("button 2")
        .finalize();
    auto h1 = xw::make_shared_holder<xw::xwidget, xw::button>(std::move(b1));
    auto h2 = xw::make_shared_holder<xw::xwidget, xw::button>(std::move(b2));
    
    xw::hbox box;
    box.add(h1);   /// need a new add method with a holder to box.
    box.add(h1);   /// 
    box.add(h2);   /// 
    return box;
}

Consider refactoring xselection

Currently xselection and xmultiple_selection only differ by one member type. It could be worth factoring the common code in a base class.

Descriptions

We lack the description attribute which is is the DescriptionWidget in ipywidgets.

C++ value semantics, RAII, widgets state and life time

xeus comms and widgets are meant to have a value semantics.

The behavior is the following

  • when a comm is created, it is registered in the comm manager
  • when a comm is destroyed, it is unregistered from the comm manager.
  • every time we copy a comm, i.e. xcomm a = b, we create a new comm with a new ID and an entry in the comm manager. This semantic is different from that of python / ipykernel / ipywidgets. Obviously it is not the case with references
  • however, when we move a comm with move constructor, no new ID is used. The address in the comm manager is simply updated.

Now, open() and close() are still independent operations from the constructor. Morally, we could also call these upon registration and unregistration, and it would probably be cleaner.

The issue that remains though, is that open can send data and metadata in the comm_open message, and it is used by the widgets framework. (We actually do that in xwidgets too when instantiating the comm). However, we still need to implement it in the case of copy and move constructors.

I have the feeling that the collapsing of the opening of the comm and the sending of the initial stat complicates the picture. I am tempted to always send two messages, one for the comm_open with no state (and implement full RAII wrt comm_open and comm_close) and manually send patches.

Consistency with IPyWidget

This issue is meant to track the evolution of the consistency with IPyWidget.

  • Update JS libraries versions
    • Update declared versions #239
    • Test for missing attributes #239
    • Update widget attributes #239
    • Implement missing styles #243
    • Add missing visual attributes: "description", "description_allow_html", "tabbable", "tooltip" #242
    • Test missing attributes schemas
  • Update protocol version #251
    • Update declared version
    • Implement echo_update feature
  • Update packaging dependency to jupyterlab_widgets

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.