@@ -180,6 +180,7 @@ class Session(ABC):
180180 output : Outputs
181181 clientdata : ClientData
182182 current_output_id : str | None
183+ "ID for the currently rendering output."
183184
184185 # Could be done with a weak ref dict from root to all children. Then we could just
185186 # iterate over all modules and check the `.bookmark_exclude` list of each proxy
@@ -1556,7 +1557,7 @@ def pixelratio(self) -> float:
15561557 """
15571558 return cast (int , self ._read_input ("pixelratio" ))
15581559
1559- def output_height (self , id : str ) -> float | None :
1560+ def output_height (self , id : Optional [ str ] = None ) -> float | None :
15601561 """
15611562 Reactively read the height of an output.
15621563
@@ -1573,7 +1574,7 @@ def output_height(self, id: str) -> float | None:
15731574 """
15741575 return cast (float , self ._read_output (id , "height" ))
15751576
1576- def output_width (self , id : str ) -> float | None :
1577+ def output_width (self , id : Optional [ str ] = None ) -> float | None :
15771578 """
15781579 Reactively read the width of an output.
15791580
@@ -1590,7 +1591,7 @@ def output_width(self, id: str) -> float | None:
15901591 """
15911592 return cast (float , self ._read_output (id , "width" ))
15921593
1593- def output_hidden (self , id : str ) -> bool | None :
1594+ def output_hidden (self , id : Optional [ str ] = None ) -> bool | None :
15941595 """
15951596 Reactively read whether an output is hidden.
15961597
@@ -1606,7 +1607,7 @@ def output_hidden(self, id: str) -> bool | None:
16061607 """
16071608 return cast (bool , self ._read_output (id , "hidden" ))
16081609
1609- def output_bg_color (self , id : str ) -> str | None :
1610+ def output_bg_color (self , id : Optional [ str ] = None ) -> str | None :
16101611 """
16111612 Reactively read the background color of an output.
16121613
@@ -1623,7 +1624,7 @@ def output_bg_color(self, id: str) -> str | None:
16231624 """
16241625 return cast (str , self ._read_output (id , "bg" ))
16251626
1626- def output_fg_color (self , id : str ) -> str | None :
1627+ def output_fg_color (self , id : Optional [ str ] = None ) -> str | None :
16271628 """
16281629 Reactively read the foreground color of an output.
16291630
@@ -1640,7 +1641,7 @@ def output_fg_color(self, id: str) -> str | None:
16401641 """
16411642 return cast (str , self ._read_output (id , "fg" ))
16421643
1643- def output_accent_color (self , id : str ) -> str | None :
1644+ def output_accent_color (self , id : Optional [ str ] = None ) -> str | None :
16441645 """
16451646 Reactively read the accent color of an output.
16461647
@@ -1657,7 +1658,7 @@ def output_accent_color(self, id: str) -> str | None:
16571658 """
16581659 return cast (str , self ._read_output (id , "accent" ))
16591660
1660- def output_font (self , id : str ) -> str | None :
1661+ def output_font (self , id : Optional [ str ] = None ) -> str | None :
16611662 """
16621663 Reactively read the font(s) of an output.
16631664
@@ -1685,9 +1686,18 @@ def _read_input(self, key: str) -> str:
16851686
16861687 return self ._session .input [id ]()
16871688
1688- def _read_output (self , id : str , key : str ) -> str | None :
1689+ def _read_output (self , id : str | None , key : str ) -> str | None :
16891690 self ._check_current_context (f"output_{ key } " )
16901691
1692+ if id is None :
1693+ id = self ._session .current_output_id
1694+
1695+ if id is None :
1696+ raise ValueError (
1697+ "session.clientdata.output_*() must be either be supplied with an id "
1698+ "or called from within an output renderer."
1699+ )
1700+
16911701 input_id = ResolvedId (f".clientdata_output_{ id } _{ key } " )
16921702 if input_id in self ._session .input :
16931703 return self ._session .input [input_id ]()
0 commit comments