Hi all,
In quite some apps, Plotly is used to generate visualizations in the WebView. Usually the go.Figure object is created in the controller. After that all kind of visualizations are added to the object from different models/objects. I am curious what your preferred method is to do this and why? I have seen several methods to do this:
- Pass the fig object as an argument and return the fig object. Possibly making the argument optional and creating the fig object in the method.
@WebView('Visualization', duration_guess=2)
def visualize(self, params, **kwargs) -> WebAndDataResult:
model1 = model(params)
fig = go.Figure()
fig = model1.get_visualization(fig)
return WebResult(html=StringIO(fig.to_html())
- pass the fig object, but do not return anything
@WebView('Visualization', duration_guess=2)
def visualize(self, params, **kwargs) -> WebAndDataResult:
model1 = model(params)
fig = go.Figure()
model1.get_visualization(fig)
return WebResult(html=StringIO(fig.to_html())
- Let the method return a list of traces and add them in the controller
@WebView('Visualization', duration_guess=2)
def visualize(self, params, **kwargs) -> WebAndDataResult:
model1 = model(params)
fig = go.Figure()
for trace in model1.get_visualizations():
fig.add_trace(trace)
return WebResult(html=StringIO(fig.to_html())
I recently changed from option 2 to 3. Because it is slightly easier to understand by more inexperienced (external) devs.
I am curious about your opinions about this.