Create an api using dash

I have created a dashboard using plotly dash. Now I wish to create an API so that the output of the analytical calculations done to show in the dashboard can be accessed from a different platform.
I can’t find a way to directly do this using just Dash. I found a couple of articles stating how dash can be embedded into a flask app. But I was wondering if there’s a way that the api can be built using just dash.

You can add API endpoints to your Dash app by accessing the underlying server connection. Check out this forum post for more information.

How to add restufl api endpoints to a dash app

I checked out that post but the issue is that when callbacks are used, the output of the callback doesn’t get accepted by the flask endpoint function. So I can’t export those outputs. Here is a simple code I’ve been trying:

df = pd.DataFrame({‘name’: [‘A’, ‘B’, ‘C’, ‘D’],
‘value’: [10, 20, 30, 40]
})

server = Flask(name)
app = dash.Dash(name=‘app1’, server=server, url_base_pathname=’/app1/’)

app.layout = dbc.Container([
dbc.Row([
dbc.Col([
dcc.Dropdown(id=‘dropdown’,
options=[{‘label’: k, ‘value’: v} for k, v in zip(df[‘name’], df[‘value’])],
value=10)
], width=4),

    dbc.Col([
        html.P(id='ptext')
    ])
])

])

@app.callback(
Output(‘intermediate_value’, ‘data’),
Input(‘dropdown’, ‘value’)
)
def ptext(dropdown):
text = dropdown + 5
return text

@server.route(’/app1/route1’)
def app2(ptext):
text = ptext()
return text

if name == ‘main’:
server.run(debug=True, port=8050)

This code throws the error:
TypeError: app2() missing 1 required positional argument: ‘ptext’

Specifically look at the solution of the post. They define the class endpoint and then add it as a resource. I’m guessing from your error you the server is not calling app2 with a parameter like you defined.