Create table with data from an API

Hi, I am trying to create a table from data from an API. I want to grab a parameter from the URL and make a call and plot a table. However, it does not work.

external_stylesheets = ['']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

def dummy():
#Get parameter from request url
#make API call here with parameter but it's not working
df = request.get('https://...')
         layout = html.Div(style= { 'backgroundColor': color['background'] }, children=[
         html.H4('US Agriculture Exports (2011)'),
     return layout

app.layout = dummy

Hi, could you use a print statement to check whether df is a valid dataframe? Also, could you post the code of generate_table so that we can check it?

Thank you for your response, I think the issue I’m having is how would I be able to grab a parameter from the URL. In this instance i see the browser is making calls to
when I call


then I see the browser making another call to get_layout


Here is the function:

def generate_table(dataframe, max_rows=10):
     return html.Table(
         # Header
         [html.Tr([html.Th(col) for col in dataframe.columns])] +

         # Body
             html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
         ]) for i in range(min(len(dataframe), max_rows))]

however dataframe should come from an API based on for example, a userId from the parameter. But it seems like that’s being stripped when call to get_layout. Does this make sense?

So the flow is:

  1. grab userId from url
  2. make call to our endpoint with userId to get user data
  3. return generateTable with that user data.