So nice! I’ve been using plotly_express for my last couple of Dash apps that I’ve made and it’s been . Charts that used to take ~15-100 lines of code now only take 2.
Highly recommend everyone take some time and check it out.
If the callback output is Output("graph_id","figure") then i usually : return {"data":trace_list}
Is it similar for using plotly express?
Can i append px.scatter(data, x="column_name", y="column_name") to a list and then return that to the data key of the figure dictionary?
@adi using px with Dash is a bit different: px.scatter() returns a Figure object which you can return directly. Now it does contain traces in a data list, but if you pull them out and return them directly you’ll be missing the corresponding layout object which is likely necessary to render properly.
First, thanks for this amazing work you’re great! Quick question: how do you define the layout properties in, for example, the px.scatter() arguments? I read in the support section that it is “A dict of string/value properties that will be passed to the Layout constructor” but i can’t figure out the way of passing it as arguments.
EDIT:
Figured it out! if you have fig = px.scatter() all you have to do before returning fig to the graph is set layout properties like this: fig.layout.font = dict(family=‘Helvetica’) and so on
@jbeyerpx will return a full figure which likely will contain multiple traces, so the recommended workflow is the one mentioned by @jorge243 i.e. either use the output of px directly or mutate it before passing it into dcc.Graph(figure=fig)
@nicolaskruchten As a test I wanted to see how Plotly Express works with Dash. The chart loads properly, but the year slider animation does not start. I am using the gapminder example from the Plotly Express guides.
import dash
import dash_html_components as html
import dash_core_components as dcc
import plotly_express as px
app = dash.Dash(__name__)
gapminder = px.data.gapminder()
app.layout = html.Div(
html.Div([
dcc.Graph(figure=px.scatter(gapminder, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country", facet_col="continent",
log_x=True, size_max=45, range_x=[100,100000], range_y=[25,90]))
])
)
if __name__ == '__main__':
app.run_server(debug=True)
@XFaCToZ2 yes, Dash doesn’t handle animation frames at the moment, so I would recommend implementing the animation controls with html buttons and a slider outside of the figure.
I don’t think we support PyCharm yet for inline display, mostly Jupyter Notebooks / JupyterLab. Hopefully within a month we will have a way to see these in PyCharm and other editors directly
In the meantime, would you recommend a different python package to achieve the time animations? Or if you have a full example using jorge’s suggestion I would be happy to use that.