Black Lives Matter. Please consider donating to Black Girls Code today.

Next steps after hello dash app?

Hello!
I was wondering, is there any blessed tutorials to work through for dash/plotly beyond that which was beyond the dash 7 part tutorial?

I have, what I think is a simple project, and it seemed like dash more than capable of handling it, but I can’t seem to get the pieces to work together.

  • simple page where you can view a table based on a CSV file.

  • text explanation at the top

  • dropdown filter where you can select a categorical value based on the unique values in that column [EG filter a company column by the company names in the CSV’s Company column] and then update the displayed table to showing just those rows that have your selection

  • Allow the user to download the table as a CSV based on their currently displayed table

In my project, I am displaying the dropdown based on a static list I made, but it would be great to make it dynamically look at the CSV the table is based on, but I am struggling to understand how to make that dropdown selection “work” past allowing a user to click an option.

Also, I haven’t seen anything for allowing a user to download the source CSV nor a CSV based on the current state of the DataTable. That’s a thing in dash, right?

Thanks in advance for any help!

Pandas would be a good place to look for both of these issues. You can use it to read the CSV, you can pull the column names from there. You can then iterate over those column names to populate drop down menus.

So in this example. You would use python to build the options.

 dcc.Dropdown(
    id='my-dropdown',
    options=[
        {'label': 'New York City', 'value': 'NYC'},
        {'label': 'Montreal', 'value': 'MTL'},
        {'label': 'San Francisco', 'value': 'SF'}
    ],
    value='NYC'
)

Here is some pseudo code… it won’t work but should give you an idea one way you can approach it.

options_list = []

def option_builder(column_name):
      menu_item = {'label' = column_name, value = column_name}
      options_list.append(menu_item)

for i in df.columns():
     option_builder(i)

dcc.Dropdown(
        id='my-dropdown',
        options=options_list,
        value=options_list[0]
    )

To export a csv. You can use pandas to save to a csv on the filesystem or to a cloud bucket. Then provide a download link

I appreciate the thoughtful reply! This is a big help.

1 Like

Happy to help… :slight_smile: