mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
44 lines
1.3 KiB
Plaintext
44 lines
1.3 KiB
Plaintext
%%md
|
|
|
|
# RustPython Notebook: python, javascript, css, markdown and math
|
|
|
|
|
|
Python in the browser is fun. Python and Javascript working together is double
|
|
the fun 😜. Markdown and math are good for communicating ideas 🤔 (especially
|
|
scientific ones). Adding css to the mix, makes everything look pretty ✨.
|
|
|
|
---
|
|
|
|
In this demo example, the RustPython Notebook:
|
|
- runs JS to create a user interface.
|
|
- the reader can input data, you can do js validation on that input.
|
|
- the dynamically created HTML element (with JS) can be made to execute a python function (on click for example)
|
|
- the data is passed from Javascript back to Python
|
|
- you can run analysis or simulation in python
|
|
- the results are displayed with python
|
|
- or data can be visualized quickly in the browser with a js vis library.
|
|
- everything is styled with css, neatly.
|
|
- everything runs in the browser, even on your phone, no servers.
|
|
- there are tabs to create multiple documents
|
|
- the split view lets you multi-task
|
|
|
|
---
|
|
|
|
%%py
|
|
|
|
# Python code
|
|
|
|
# you have access to helpers for emitting p & h1-h6
|
|
h2("Calculator")
|
|
h3("Enter your lucky number")
|
|
|
|
inp1 = add_text_input()
|
|
inp2 = add_text_input()
|
|
|
|
@add_button("click me to add")
|
|
def run_model():
|
|
a, b = int(inp1()), int(inp2())
|
|
set_output(f"<pre>{a} + {b} = <b>{a + b}</b></pre>")
|
|
|
|
set_output = add_output()
|