Hi all, just started working with Dash and Plotly and loving it so far, so decided to join the community!
I am working on building an app for my research team that will aid some of my colleagues create “better” and more consistent plots for their presentations in a simple way. The hope is to utilize dcc.Upload to allow users to upload any number of CSV or Excel files that have common sets of data (e.g., stress-strain curves with one file/dataset per curve). From there, I would like to use DataTables to display each of the datasets for quick viewing purposes prior to setting up some dropdowns or such to pick x- and y-data to be plotted from the uploaded data.
That brings me to my question. Is it possible to combine multiple DataTables together with pagination such that each table is not displayed simultaneously? Since I am allowing an arbitrary number of files to be uploaded, there could potentially be many more tables than I’d like to display on a page at once.
I tried simply passing a list of dictionaries to the DataTable component, but that didn’t work. Passing a list of DataTables provided the undesired output: two DataTables stacked on top of each other on the page. See basic example of the two approaches I tried below:
from dash import Dash, html, dcc, dash_table
import dash_bootstrap_components as dbc
import pandas as pd
app = Dash(__name__)
# Sample dataframes. There would be any number of these types of similar datasets uploaded by the user.
df_1 = pd.DataFrame({"stress": [0, 1, 2, 3], "strain": [0.0, 0.1, 0.2, 0.3]})
df_2 = pd.DataFrame({"stress": [0, 1.5, 2.5, 3.5], "strain": [0.0, 0.11, 0.21, 0.31]})
## Approach 1
# Attempting to pass a list of dictionaries to the DataTable, but an error is displayed on the page.
tables = dash_table.DataTable(data=[df.to_dict("records") for df in [df_1, df_2]])
## Approach 2
# Attempting to create a list of DataTables, but this just stacks the two tables one after the other.
tables = [
dash_table.DataTable(
data=df.to_dict("records"),
)
for df in [df_1, df_2]
]
app.layout = dbc.Container([dbc.Row([dbc.Col(tables)])])
if __name__ == "__main__":
app.run_server(debug=True)
If what I’m trying to do isn’t possible, does anyone have a recommendation of an alternative that achieves something nice and clean like my original intent?
Thank you!