How to write a Minimal Reproducible Example (MRE)

Adding a minimal reproducible example to your questions will help attract community members to answer your question. The goal of writing a MRE is to allow other members of the community to run the code on their computers and “reproduce” the error, so that they can best help you.
Please make sure that your MRE includes data and that the code is correctly pre-formatted.
To preformat, copy and paste the code in your post and then click on </> (Preformatted text), as shown on the image:

Here’s a good MRE example:

I noticed on my Dash DataTables, that headers for the table suddenly stopped respecting the style_header ‘text-align’: ‘center’ instruction when running under Dash v2.1.0. After debugging, I backed down to Dash v2.0.0 and it resolved the issue. Can you please help me understand why this is happening?

import dash
from dash import dash_table
import pandas as pd


app = dash.Dash(
    __name__
)

app.layout = dash_table.DataTable(
    columns=[
        {"name": ["", "Year"], "id": "year"},
        {"name": ["City", "Montreal"], "id": "montreal"},
        {"name": ["City", "Toronto"], "id": "toronto"},
        {"name": ["City", "Ottawa"], "id": "ottawa"},
        {"name": ["City", "Vancouver"], "id": "vancouver"},
        {"name": ["Climate", "Temperature"], "id": "temp"},
        {"name": ["Climate", "Humidity"], "id": "humidity"},
    ],
    data=[
        {
            "year": i,
            "montreal": i * 10,
            "toronto": i * 100,
            "ottawa": i * -1,
            "vancouver": i * -10,
            "temp": i * -100,
            "humidity": i * 5,
        }
        for i in range(10)
    ],
    style_header={
            'text-align': 'center',
        },
    merge_duplicate_headers=True,
)

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

As you can see from the Minimal Reproducible Example (MRE) above, we built our data inside the code. However, you can also use built-in data that plotly express provides for other MREs you might write. Here are all the plotly datasets.

For example, if you’d like to use the election dataset for your post, you can access it like this:

import plotly.express as px
df = px.data.election()
print(df.head())

Please do let us know if you have further doubts about how to write a Minimal Reproducible Example :slight_smile:

Happy coding!

8 Likes

Hey @davi

This is a super helpful post - thanks for writing it up!

I also like that you used a “real world” example. This was the MRE from @geneblandjr excellent post which lead to a bug getting fixed in latest Dash release V2.2.0 :confetti_ball:

3 Likes

Sometimes, attaching screenshots can also make the problem description clearer.

3 Likes