forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.txt
More file actions
43 lines (31 loc) · 1.3 KB
/
main.txt
File metadata and controls
43 lines (31 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
%%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()