It's React, but in Python
Project description
reactpy-jupyter
A client for ReactPy implemented using Jupyter widgets
Try It Now!
Check out some live examples by clicking the badge below:
Getting Started
To install use pip
:
pip install reactpy_jupyter
Then, before anything else, do one of the following:
-
At the top of your notebook run
import reactpy_jupyter
-
Register
reactpy_jupyter
as a permanant IPython extension in your config file:c.InteractiveShellApp.extensions = [ 'reactpy_jupyter' ]
Usage
Once you're done getting started, you can author and display ReactPy layouts natively in your Jupyter Notebook:
import reactpy
@reactpy.component
def ClickCount():
count, set_count = reactpy.hooks.use_state(0)
return reactpy.html.button(
{"onClick": lambda event: set_count(count + 1)},
[f"Click count: {count}"],
)
ClickCount()
You can also turn an reactpy
element constructor into one that returns an ipywidget
with
the reactpy_juptyer.widgetize
function. This is useful if you wish to use ReactPy in combination
with other Jupyter Widgets as in the following example:
ClickCountWidget = reactpy_jupyter.widgetize(ClickCount)
ipywidgets.Box(
[
ClickCountWidget(),
ClickCountWidget(),
]
)
Alternatively just wrap an reactpy
element instance in an reactpy_jupyter.LayoutWidget
:
ipywidgets.Box(
[
reactpy_jupyter.LayoutWidget(ClickCount()),
reactpy_jupyter.LayoutWidget(ClickCount()),
]
)
For a more detailed introduction check out this live demo here:
Development Installation
For a development installation (requires Node.js and Yarn version 1),
$ git clone https://github.com/reactive-python/reactpy-jupyter.git
$ cd reactpy-jupyter
$ pip install -e .
To automatically re-build and refresh Jupyter when making changes start a Vite dev server:
$ npx vite
Then, before importing reactpy_jupyter
set the following environment variable:
import os
os.environ["REACTPY_JUPYTER_DEV"] = "1"
import reactpy_jupyter
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file reactpy_jupyter-0.8.1.tar.gz
.
File metadata
- Download URL: reactpy_jupyter-0.8.1.tar.gz
- Upload date:
- Size: 175.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 284b823eaa03d75887639d9acf5a31e0373d7ac44451cb2f7c6a7a5fd5ea72cb |
|
MD5 | a136f1828543ac2b818d1c0c0e25f2e3 |
|
BLAKE2b-256 | 90f4d953c10a2c3d5f0050d512f510c3d42b99ddca3eaebf6d1b7c3c42305ba1 |
File details
Details for the file reactpy_jupyter-0.8.1-py3-none-any.whl
.
File metadata
- Download URL: reactpy_jupyter-0.8.1-py3-none-any.whl
- Upload date:
- Size: 174.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b698fd5e2ae2297972e32391604c436f4b0086d795fc7cedb09e39c488760588 |
|
MD5 | 2b24cc02bfecf6a4b5381ded0dcaab42 |
|
BLAKE2b-256 | 921046b7c43fe0c734f01a6b93178059921b4905ffba9dd3f9993de523f92e4f |