diff --git a/src/viser/_gui_api.py b/src/viser/_gui_api.py index f56e0cd70..cf4891082 100644 --- a/src/viser/_gui_api.py +++ b/src/viser/_gui_api.py @@ -560,6 +560,7 @@ def add_gui_plotly( self._setup_plotly_js = True # After plotly.min.js has been sent, we can send the plotly figure. + # Empty string for `plotly_json_str` is a signal to the client to render nothing. self._get_api()._queue( _messages.GuiAddPlotlyMessage( order=handle._order, diff --git a/src/viser/client/src/components/PlotlyComponent.tsx b/src/viser/client/src/components/PlotlyComponent.tsx index c3e5990a5..39cec0071 100644 --- a/src/viser/client/src/components/PlotlyComponent.tsx +++ b/src/viser/client/src/components/PlotlyComponent.tsx @@ -16,6 +16,9 @@ const PlotWithAspect = React.memo(function PlotWithAspect({ aspectRatio: number; staticPlot: boolean; }) { + // Catch if the jsonStr is empty; if so, render an empty div. + if (jsonStr === "") return
; + // Parse json string, to construct plotly object. // Note that only the JSON string is kept as state, not the json object. const plotJson = JSON.parse(jsonStr);