Skip to content

feat(clientdata): id is now optional on clientdata.output_*() methods #1978

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Apr 22, 2025

See the changes to CHANGELOG for a description of what this PR adds.

A minimal example:

import matplotlib.pyplot as plt
import numpy as np

from shiny.express import render, session, ui

ui.input_dark_mode()

@render.plot
def myplot():
    plt.figure()
    plt.hist(np.random.normal(size=100))  # type: ignore

    bg_color = session.clientdata.output_bg_color()
    plt.title(f"bgcolor: {bg_color}")
Screenshot 2025-04-22 at 6 18 30 PM Screenshot 2025-04-22 at 6 18 52 PM

@cpsievert cpsievert force-pushed the feat/current_output_id branch from d7e3815 to 088ef7b Compare April 22, 2025 23:21
@cpsievert cpsievert force-pushed the feat/current_output_id branch from 088ef7b to e97b0f0 Compare April 22, 2025 23:23
@cpsievert cpsievert requested a review from Copilot April 23, 2025 15:07
Copilot

This comment was marked as outdated.

@cpsievert cpsievert changed the title feat(session): add current_output_id attribute and make id optional on clientdata output methods feat(Session): add .current_output_id() method and make id optional on clientdata.output_*() methods Apr 23, 2025
@cpsievert cpsievert requested a review from Copilot April 23, 2025 23:15
Copilot

This comment was marked as off-topic.

@cpsievert cpsievert marked this pull request as ready for review April 23, 2025 23:17
@cpsievert cpsievert requested a review from schloerke April 23, 2025 23:17
Comment on lines 412 to 426
@contextmanager
def _current_output_id(self):
from ...session import get_current_session

session = get_current_session()
if session is None:
yield
return

old_id = session._current_output_id
try:
session._current_output_id = self._renderer.output_id
yield
finally:
session._current_output_id = old_id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach!, but I feel it is in the wrong place.

👀 for a different location.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, we ended up not finding a better place?

@cpsievert cpsievert changed the title feat(Session): add .current_output_id() method and make id optional on clientdata.output_*() methods feat(clientdata): id is now optional on clientdata.output_*() methods May 1, 2025
@cpsievert cpsievert requested a review from schloerke May 1, 2025 18:07
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