posit-dev / py-shinywidgets

Render ipywidgets inside a PyShiny app
MIT License
47 stars 5 forks source link

`reactive_read()` now throws more informative errors #120

Closed cpsievert closed 1 year ago

cpsievert commented 1 year ago

With this change, if you try to reactive_read() a non-existant or non-trait widget attribute, you'll get an informative error. For example:

import ipyleaflet as L
from htmltools import css
from shiny import *

from shinywidgets import output_widget, reactive_read, register_widget

app_ui = ui.page_fluid(
    output_widget("map"),
    ui.output_text("foo"),
)

def server(input, output, session):

    map = L.Map(center=(52, 360), zoom=4)
    register_widget("map", map)

    @output
    @render.text
    def foo():
        reactive_read(map, "foo")

app = App(app_ui, server)
Screenshot 2023-11-16 at 3 47 27 PM

Note that this'll also improve a situation like https://github.com/posit-dev/py-shinywidgets/issues/112, where jcharts.selections itself isn't a trait but does inherit from traitlets.HasTraits