metaperl / pure-python-web-development Goto Github PK
View Code? Open in Web Editor NEWAvoid the CSS/JS/HTML soup - develop web apps entirely in Python
Home Page: https://metaperl.github.io/pure-python-web-development/
Avoid the CSS/JS/HTML soup - develop web apps entirely in Python
Home Page: https://metaperl.github.io/pure-python-web-development/
While the existing Shiny implementation is great, it does have a bit of unnecessary complexity around figuring out which tasks to remove. I put together an alternative example which uses insert and remove ui.
import shinyswatch
from htmltools import tags
from shiny import App, module, reactive, render, ui
app_ui = ui.page_fixed(
{"class": "my-5"},
tags.style(
"""
.row {
border-bottom: 1px solid #eeeeee;
border-top: 1px solid #eeeeee;
margin-top: -1px;
padding: 20px 10px;
align-items: center;
}
.row p {
margin-bottom: 0px;
}
"""
),
shinyswatch.theme.minty(),
ui.panel_title("Shiny TodoMVC"),
ui.layout_sidebar(
ui.panel_sidebar(
ui.input_text("todo_input_text", "", placeholder="Todo text"),
ui.input_action_button("add", "Add to-do"),
),
ui.panel_main(
ui.output_text("cleared_tasks"),
ui.div(id="tasks", style="margin-top: 0.5em"),
),
),
)
def server(input, output, session):
finished_tasks = reactive.Value(0)
task_counter = reactive.Value(0)
@output
@render.text
def cleared_tasks():
return f"Finished tasks: {finished_tasks()}"
@reactive.Effect
@reactive.event(input.add)
def add():
counter = task_counter.get() + 1
task_counter.set(counter)
id = "task_" + str(counter)
ui.insert_ui(
selector="#tasks",
where="afterBegin",
ui=task_ui(id),
)
# Since we want the action button inside the module to update
# the finished_tasks global counter, we need to pass the reactive values list
# down to the module function.
task_server(
id, remove_id=id, task_list=finished_tasks, text=input.todo_input_text()
)
ui.update_text("todo_input_text", value="")
# Modules to define the rows
@module.ui
def task_ui():
out = ui.output_ui("button_row")
return out
@module.server
def task_server(input, output, session, remove_id, task_list, text):
finished = reactive.Value(True)
@output
@render.ui
def button_row():
if finished():
button_text = "finish"
button_class = "btn-default"
text_style = ""
else:
button_text = "clear"
button_class = "btn-warning"
text_style = "text-decoration: line-through"
out = ui.row(
{"id": remove_id, "style": "margin: 10px, border: 1px solid #ddd"},
ui.column(
4,
ui.input_action_button(
button_text, button_text.capitalize(), class_=button_class
),
),
ui.column(
8,
ui.p(text, style=text_style),
),
)
return out
@reactive.Effect
@reactive.event(input.finish)
def finish_task():
task_list.set(task_list.get() + 1)
finished.set(False)
@reactive.Effect
@reactive.event(input.clear)
def clear_task():
ui.remove_ui(selector=f"div#{remove_id}")
app = App(app_ui, server)
Thanks for the great resource, it was super great to see all of these frameworks in one place with at least one example apps. I'm one of the devs on Shiny, and just wanted some clarification on this sentence:
"Like many class B solutions, it lacks the features for complete web applications โ authentication, authorization and sessioning."
Shiny is built on the same stack as FastAPI so there's a lot of ways to authenticate it. Our professional products also support authentication.
Shiny also has session objects which can be accessed by the application process. Depending on the authentication method this can also be used to change app behaviour based on the logged-in user.
So overall it seems pretty similar to Solara and Dash, which are both in class A. Can you provide more detail on what you mean by authentication/authorization or sessioning?
Hi @metaperl ...
Just found the page https://metaperl.github.io/pure-python-web-development/todomvc.html
And i've made a "TODOMVC" with htag ;-)
Here it is : https://github.com/manatlan/htag/blob/main/examples/todomvc.py
this "todomvc" is integrated in my pyscript/html demo's page
https://raw.githack.com/manatlan/htag/main/examples/pyscript_demo.html?115-todomvc.py
(so it will be possible to edit/test/run (like repl, but on client side, with pyscript tech ! no python required!))
if you have no time, i could submit a PR, sure!
to inform you about recent htag's developments.
best regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.