1111__author__ = "Jonas Van Der Donckt, Jeroen Van Der Donckt, Emiel Deprost"
1212
1313import warnings
14- from typing import Tuple
14+ from typing import Tuple , List
1515
1616import dash
1717import plotly .graph_objects as go
@@ -41,6 +41,7 @@ def __init__(
4141 show_mean_aggregation_size : bool = True ,
4242 convert_traces_kwargs : dict | None = None ,
4343 verbose : bool = False ,
44+ show_dash_kwargs : dict | None = None ,
4445 ):
4546 # `pr_props`` is a variable to store properties of a plotly-resampler figure
4647 # This variable will only be set when loading a pickled plotly-resampler figure
@@ -85,6 +86,8 @@ def __init__(
8586 # A single trace dict or a list of traces
8687 f .add_traces (figure )
8788
89+ self ._show_dash_kwargs = show_dash_kwargs if show_dash_kwargs is not None else {}
90+
8891 super ().__init__ (
8992 f ,
9093 convert_existing_traces ,
@@ -155,6 +158,8 @@ def show_dash(
155158 See more https://dash.plotly.com/dash-core-components/graph
156159 **kwargs: dict
157160 Additional app.run_server() kwargs. e.g.: port
161+ Note that these kwargs take precedence over the ones passed to the
162+ constructor via the ``show_dash_kwargs`` argument.
158163
159164 """
160165 graph_properties = {} if graph_properties is None else graph_properties
@@ -175,14 +180,19 @@ def show_dash(
175180
176181 # 2. Run the app
177182 if (
178- self .layout .height is not None
179- and mode == "inline"
183+ mode == "inline"
180184 and "height" not in kwargs
181185 ):
182- # If figure height is specified -> re-use is for inline dash app height
183- kwargs ["height" ] = self .layout .height + 18
186+ # If app height is not specified -> re-use figure height for inline dash app
187+ # Note: default layout height is 450 (whereas default app height is 650)
188+ # See: https://plotly.com/python/reference/layout/#layout-height
189+ fig_height = self .layout .height if self .layout .height is not None else 450
190+ kwargs ["height" ] = fig_height + 18
191+
192+ # kwargs take precedence over the show_dash_kwargs
193+ kwargs = {** self ._show_dash_kwargs , ** kwargs }
184194
185- # store the app information, so it can be killed
195+ # Store the app information, so it can be killed
186196 self ._app = app
187197 self ._host = kwargs .get ("host" , "127.0.0.1" )
188198 self ._port = kwargs .get ("port" , "8050" )
@@ -238,3 +248,11 @@ def register_update_graph_callback(
238248 dash .dependencies .Input (graph_id , "relayoutData" ),
239249 prevent_initial_call = True ,
240250 )(self .construct_update_data )
251+
252+ def _get_pr_props_keys (self ) -> List [str ]:
253+ # Add the additional plotly-resampler properties of this class
254+ return super ()._get_pr_props_keys () + ["_show_dash_kwargs" ]
255+
256+ def _ipython_display_ (self ):
257+ # To display the figure inline as a dash app
258+ self .show_dash (mode = "inline" )
0 commit comments