Giter VIP home page Giter VIP logo

pure-python-web-development's People

Contributors

manatlan avatar metaperl avatar rodja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pure-python-web-development's Issues

Alternative Shiny implementation

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)

Clarification on Shiny

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?

add the htag's todomvc ?

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.

  • will release a "1.0.0" soon
  • I've just created another "htag runner" (outside of the main htag module) named htagweb, which is available as another lib on pypi, which provide a more robust "http server" for hosting "htag app" over the web (with sessions, real process management, multiple gunicorn workers, etc ...). On which, it's easy to manage an oauth2 flow (with authlib), I will provide an example soon. It was not the main goal of htag at start, but now, it's a reality : htag's apps can be served, in a decent way on the web ... see https://www.mlan.fr (which is my main dev/server for "htag on the web").

best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.