Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render_widget now attaches it's return value to the decorated function #119

Merged
merged 10 commits into from
Jan 16, 2024

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Nov 15, 2023

This PR helps solve the problem of needing a widget object in scope if you want to set/get attribute values, and thus, effectively eliminates any need for register_widget()

TODO

  • When the decorated function re-renders, anyone would read the value should get invalidated.
  • Can we provide typing/autocomplete on render_func.widget/render_func.value?
  • Deprecate register_widget()?
    • Should only do this if we can do typing properly
  • Update overview to reflect the new mental "proxy" model

Example/testing app

import ipyleaflet as ipyl
from shiny import reactive, render, ui
from shiny.express import input

from shinywidgets import reactive_read, render_widget

print("A")

@render.text
def center():
    print("@render.text")
    cntr = reactive_read(map.widget, 'center')
    return f"Current center: {cntr}"

print("B")

@render_widget
def map():
    print("@render_widget")
    return ipyl.Map(zoom=input.zoom(), center=(0, 0))

print("C")
print("Widget value:", map.widget)

ui.input_slider("zoom", "Zoom", min=1, max=7, value=2, step=0.5)

@cpsievert cpsievert force-pushed the widget-proxy branch 2 times, most recently from 539b803 to c52db3d Compare November 15, 2023 23:33
@cpsievert cpsievert requested a review from schloerke November 16, 2023 15:28
@cpsievert cpsievert force-pushed the widget-proxy branch 4 times, most recently from 96d88fd to 2affb72 Compare November 20, 2023 21:21
@schloerke
Copy link
Collaborator

  • Can we provide typing/autocomplete on render_func.widget/render_func.value?

We currently have support for render_func.value, but not for render_func.widget. To get render_func.widget, we'd need to have special methods like @render_plotly as the widget class is not provided by the user but could be provided by the renderer's typing.

I've added a commented render_plotly method as a working prof-of-concept

@schloerke
Copy link
Collaborator

  • Deprecate register_widget()?

See #127 . This can be done in a followup PR

@schloerke
Copy link
Collaborator

I am strongly against doing render_fn.value or render_fn.widget and have it call any reactivity.

py-shiny did not implement reactive values for clarity. I'm going to continue with that approach and make helper methods for reactive_read() / reactive_depend() on the render_widget class.

@cpsievert cpsievert marked this pull request as ready for review January 16, 2024 23:15
@cpsievert cpsievert merged commit 4451359 into main Jan 16, 2024
5 checks passed
@cpsievert cpsievert deleted the widget-proxy branch January 16, 2024 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants