Giter Club home page Giter Club logo

anywidget's Introduction

anywidget

PyPI License codecov Open In Colab DOI

custom jupyter widgets made easy

  • ๐Ÿ› ๏ธ create widgets without complicated cookiecutter templates
  • ๐Ÿ“š publish to PyPI like any other Python package
  • ๐Ÿค– prototype within .ipynb or .py files
  • ๐Ÿš€ run in Jupyter, JupyterLab, Google Colab, VSCode, and more
  • โšก develop with instant HMR, like modern web frameworks

Learn more in the Jupyter blog.

Installation

anywidget is available on PyPI:

pip install "anywidget[dev]"

and also on conda-forge:

conda install -c conda-forge anywidget

Usage

import anywidget
import traitlets

class CounterWidget(anywidget.AnyWidget):
    # Widget front-end JavaScript code
    _esm = """
    function render({ model, el }) {
      let button = document.createElement("button");
      button.innerHTML = `count is ${model.get("value")}`;
      button.addEventListener("click", () => {
        model.set("value", model.get("value") + 1);
        model.save_changes();
      });
      model.on("change:value", () => {
        button.innerHTML = `count is ${model.get("value")}`;
      });
      el.appendChild(button);
    }
    export default { render };
    """
    # Stateful property that can be accessed by JavaScript & Python
    value = traitlets.Int(0).tag(sync=True)

Front-end code can also live in separate files (recommend):

import pathlib
import anywidget
import traitlets

class CounterWidget(anywidget.AnyWidget):
    _esm = pathlib.Path("index.js")
    _css = pathlib.Path("styles.css")
    value = traitlets.Int(0).tag(sync=True)

Read the documentation to learn more.

Support

Having trouble? Get help in our Discord or open a Discussion.

Contributing

New contributors welcome! Check out our Contributors Guide for help getting started.

Join us on Discord to meet other maintainers. We'll help you get your first contribution in no time!

License

MIT

anywidget's People

Contributors

manzt avatar dependabot[bot] avatar github-actions[bot] avatar tlambert03 avatar kolibril13 avatar rgbkrk avatar davidbrochart avatar dvdkouril avatar bnavigator avatar gereleth avatar domoritz avatar donmccurdy avatar hbredin avatar jtpio avatar jonmmease avatar manonmarchand avatar keller-mark avatar nvictus avatar giswqs avatar rmorshea avatar

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.