posit-dev / py-shiny

Shiny for Python
https://shiny.posit.co/py/
MIT License
1.3k stars 78 forks source link

Consider supporting anonymous render functions in express #933

Open cpsievert opened 10 months ago

cpsievert commented 10 months ago

Right now express requires that rendering functions be named, but it seems like we could allow for anonymous functions?

from shiny import render
import shiny.express

@render.text
def _():
    return "Some text output"
jcheng5 commented 10 months ago

This might be possible but we can't use a randomly generated ID, if that's what you were thinking. The Express app code is run once to generate the UI, and then once for each session, so random IDs wouldn't match up. It might be possible to base it off of the decorated function's source file and line number. Anyway, it's not totally trivial.