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

DataTable from API request not functioning

I have a pretty simple program going, pulling in some data from a spacex API and looking to visualize it with dash. Not sure what’s going wrong here. ‘Error loading layout’ is the error I’m getting on the server UI.

import dash
import dash_table
import pandas as pd
import requests
import json

url = “https://api.spacexdata.com/v3/launches
data = requests.get(url)
data_dict = data.json()
data_df = pd.DataFrame.from_dict(data_dict)
print(data_df)

app = dash.Dash(name)
app.layout = dash_table.DataTable(
id=‘table’,
columns=[{“name”: i, “id”: i} for i in data_df.columns],
data=data_df,
)
if name == ‘main’:
app.run_server(debug=True)

Hi @steel welcome to the community. When you print(data_df) does that give you what you want? Is the main problem only with the layout?
One problem might be the first line of code on the second part. In my apps, I use:

app = dash.Dash(__name__)

And it’s usually better to put your DataTable inside a div right after the app.layout=…

Hey Adam, thanks. Yes print(data_df) works fine. There is a bit of a problem with formatting in my question, it should show

app = dash.Dash(__ name __)

So far I’ve created a new df with only some of the columns of the original and i’m finding that the layout is fine that way. So there must be some weirdness with the datatype or data size of one or more of the columns in the original df pulled from SpaceX API.

Great. I’m glad you found the problem :+1:

Indeed. Thanks for the introduction!