đź“Ł Dash 2.13.0 Released - Coupling with Plotly.py, Shapes in Legends, and Broader DataFrame Support

Update : version 2.15.0 has been released since this was posted.

We’re excited to announce that Dash 2.13.0 has been released :rocket:

pip install dash==2.13.0

Official Changelog :arrow_forward: Dash v2.13.0

Highlights :arrow_down_small:

Coupling with Plotly.js

The dcc.Graph component leverages the Plotly.js library to render visualizations.

Starting from Dash v2.13.0 and later, the dcc.Graph component uses the version of the Plotly.js library in the Plotly.py (aka the plotly package) version you have installed (each version of Dash prior to 2.13.0 included its own version of Plotly.js).

Previously, the dash package bundled its own version of plotly.js independently of the plotly package. This could lead to confusing issues where you might be using a new graphing feature in plotly within a Jupyter Notebook but then that feature wouldn’t be available in your Dash apps. Now Dash uses the same version in the plotly package - much more clear!

For example, if you were to pip install plotly 5.15.0, you can see in the Plotly.py releases page that this version of Plotly includes Plotly.js version 2.24.1. As a result, the dcc.Graph in your Dash app will use all features that come with Plotly.js 2.24.1.

If you prefer to use a different version of Plotly.js in Dash 2.13.0 or later, you can install a different version of Plotly.py.

In all versions of Dash you can also override the Plotly.js version by placing a Plotly.js bundle in the assets directory.


Plotly.py & dcc.Graph Updates

Updated Plotly.js from version 2.24.2. to version 2.25.2

The version of Plotly.js that is built in here is the same one that is bundled with the recently released Plotly.py 5.16.1, so we recommend that you upgrade to Plotly 5.16.1 to get the full benefit of all of these libraries working together.

pip install plotly==5.16.1

Official Changelog :arrow_forward: Plotly v5.16.1

:arrow_right: dcc.Graph -

“Equal Earth” projection recommended by NASA

Equal Earth is a fairly recent equal-area pseudocylindrical projection, which has has been adopted by the NASA Goddard Institute for Space Studies. Thanks to @apparebit , it is now part of the geo projection types.

from dash import Dash, html, dcc
import plotly.express as px

df = px.data.gapminder().query("year==2007")
fig = px.choropleth(df, locations="iso_alpha",
                    color="lifeExp",
                    hover_name="country",
                    color_continuous_scale=px.colors.sequential.Plasma)

fig.update_geos(projection_type="equal earth")

app = Dash(__name__)
app.layout = html.Div([
    dcc.Graph(figure=fig)
])

if __name__=='__main__':
    app.run()

Shapes in the Legend

You can add a shape to the legend by setting showlegend=True on the shape. In the example below we add a dotted line to the legend to highlight the 2018 baseline.

The name that appears for the shape in the legend is the shape’s name if it is provided. If no name is provided, the shape label’s text is used. If neither is provided, the legend item appears as "shape ".

from dash import Dash, html, dcc
import plotly.express as px

df = px.data.stocks(indexed=True)

fig = px.line(df)
fig.add_shape(
    showlegend=True,
    type="line",
    x0=min(df.index),
    y0=1,
    x1=max(df.index),
    y1=1,
    line_width=3,
    line_dash="dot",
    label=dict(
        text="Jan 1 2018 Baseline",
        textposition="end",
        font=dict(size=20, color="blue"),
        yanchor="top",
    ),
)


app = Dash(__name__)
app.layout = html.Div([
    dcc.Graph(figure=fig)
])

if __name__=='__main__':
    app.run()

Broader DataFrame Support

As of Plotly version 5.16, you can provide any type of DataFrame to the data_frame argument to px calls if that DataFrame supports the Python dataframe interchange protocol or has a toPandas or to_pandas_df method.

This includes DataFrames beyond Pandas like Vaex, Spark, Polars, cuDF.

Even if the DataFrame that you are using supports the Python dataframe interchange protocol, you’ll need to have Pandas version 2.0.3 or later installed. If you are using an earlier version of Pandas, Plotly Express will look for a to_pandas, toPandas, and to_pandas_df method, and use whichever one is available.

from dash import Dash, html, dcc
import polars as pl
import pandas as pd
import plotly.express as px

df_polars = pl.read_csv('FS_sp500_Value.csv')

pl_filtered = df_polars.filter(pl.col('Ticker') == 'ACN')
fig = px.line(pl_filtered, x='Date', y='High', title='Plotly with Polars (ACN stock)')

app = Dash(__name__)
app.layout = html.Div([
    dcc.Graph(figure=fig)
])


if __name__=='__main__':
    app.run_server(debug=True)


Notable Bug Fixes, Additions & Minor Changes -

Dash:

Changed

  • #2593 dcc.Input accepts a number for its debounce argument
  • #2573 Use julia --project command inside JuliaRunner.
  • #2579 Add warning if using JupyterDash

Fixed

  • #2619 Fix for dash-table column IDs containing special characters
  • #2616 Add mapping of tsconfig compiler option moduleResolution, fixes #2618
  • #2596 Fix react-dom throwing unique key prop error for markdown table, fix #1433
  • #2589 CSS for input elements not scoped to Dash application
  • #2599 Fix background callback cancel inputs used in multiple callbacks and mixed cancel inputs across pages.
  • #2578 Disable jupyter dash in Databricks

Plotly:

Added

  • Add “Equal Earth” projection to geo subplots [#6670], with thanks to @apparebit for the contribution!
  • Add options to include legends for shapes and newshape [#6653]
  • Add Plotly.deleteActiveShape command [#6679]

Changed

  • Update Croatian translations in hr locale [#6690], with thanks to @Mkranj for the contribution!

Fixed

  • Fix potential prototype pollution in plot API calls [#6703, 6704]
  • Fix clearing legend using react (regression introduced in 2.25.0) [#6695]
  • Fix contour plot colorscale domain (take account of zmin, zmax, cmin and cmax) [#6625], with thanks to @lvlte for the contribution!
  • Fix text markers on non-mapbox styled maps [#6652], with thanks to @baurt for the contribution!
  • Fix unhide isolated traces in multi legend cases (regression introduced in 2.24.3) [#6684]
  • Fix double clicking one item in a legend hides traces in other legends [#6655]
  • Fix double click pie slices when having multiple legends [#6657]
  • Fix per legend group and traceorder defaults when having multiple legends [#6664]

Previous Releases

:mega: Dash 2.11.0 Released - Dash in Jupyter, Locked Flask versions, and dcc.Graph Updates
:mega: Dash 2.9.2 Released - Partial Property Updates, Duplicate Outputs, dcc.Geolocation, Scatter Group Attributes
:mega: Dash 2.7 Released - Directional Arrows Feature, Map Bounds, and DataTable Filter Text
:mega: Dash 2.6 Released - Background Callbacks, Unit Testing, Persistent Selections, Dropdown Features
:mega: Dash 2.5 Released - Easier Multi-Page Apps, Component Properties
:mega: Dash 2.4 Released - Improved Callback Context, Clientside Promises, Typescript Components, Minor Ticks
:mega: Dash 2.3.0 Release - MathJax and fillpattern option in scatter trace
:mega: Dash 2.2.0 Release - Adds ticklabelstep to axes, and added dash.get_asset_url
:mega: Dash 2.1.0 Release - Autogenerated IDs and reärranged keyword arguments in Dash components

4 Likes