Skip to content

Instantly share code, notes, and snippets.

View rmorshea's full-sized avatar

Ryan Morshead rmorshea

View GitHub Profile
from idom import html
# <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
# <div class="modal-dialog">
# <div class="modal-content">
# <div class="modal-header">
# <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
# <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
# </div>
@rmorshea
rmorshea / nox_groups.py
Created February 13, 2023 03:03
A way to define groups of sessions with a common set of cli parameters.
from __future__ import annotations
import argparse
import inspect
import functools
from typing import Any, Callable, TypeVar, get_type_hints
import nox
from nox.sessions import Session
@rmorshea
rmorshea / reactpy-v2.md
Last active July 10, 2023 08:22
ReactPy in the Browser

A Vision for ReactPy 2.0 (maybe 3.0?)

Currently, ReactPy runs entirely server-side - all views are rendered, and their state is maintained on the server. This is how most other applications that have given Python the ability to drive interactivity have been built. Examples can be found in:

  • IpyWidgets
  • Solara
  • Streamlit
  • Pynecone

This design has opened up a whole world of possibilities for applications written purely with Python, however it has a significant drawback. In particular, this approach of requiring the server to retain a client's state and render views means that you are fundamentally limited in how many users you can serve. In many cases this has meant that these tools tend to be used to build interal data apps that serve a small number of users. Traditionally built applications avoid this problem by delegating much of this work to the client, only reaching out to a server when absolutely necessary. Even though tools like PyScript and Pyodide now allow Python to run client-side, with that

@rmorshea
rmorshea / reactpy.html
Created July 9, 2023 22:15
ReactPy + PyScript
<html>
<head>
<title>ReactPy</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<div id="root"></div>
<py-config>
@rmorshea
rmorshea / poor_mans_use_state.py
Last active July 10, 2023 19:40
Poor Man's Use State Hook
from contextlib import contextmanager
def use_state(value):
hook = current_hook()
state = hook.use_state(lambda: {"value": value})
return state["value"], lambda new_value: state.__setitem__("value", new_value)
def current_hook():