Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Possibility to call Dash server with HTTP request #1787

Open
JakubPluta opened this issue Sep 30, 2021 · 0 comments
Open

Comments

@JakubPluta
Copy link

Hey there!

I wrote a topic a couple of days ago on the community forum but would like to ask also here, and maybe if this feature is not available but it's possible to add it to start a discussion what you think about it.

I have a requirement that I need to call the dash server with my application using HTTP requests. Let's say that I have my application under url localhost:8000/app. In this application, I have a simple callback in which I am creating my figure based on some dropdown menu values. In this callback, I added a very simple feature for parsing URL parameters. And what I want to achieve is to call my application URL with an HTTP request, because inside callback I have a logic that whenever user pass in the URL in query string ?download=true then inside my callback figure will be saved to a png file using Plotly library.

So is it possible to make HTTP requests to the dash application?

I tried to make HTTP requests with the curl and python requests module, but it seems that the dash server doesn’t see this request, but on the other hand, if I directly go do the localhost:8000/app?download=true in my web browser then saving the image locally in png format works, but if I do this programmatically it doesn’t.

So here is sample of code to make it more clear:

# req.py

import requests

def make_request():
    url = "localhost:8000/app?download=ture"
    r = requests.get(url)
# app.py

....

@app.callback(
    Output(component_id="bar-chart", component_property="figure"),
    [Input(component_id="url", component_property='href')],

    prevent_initial_call=False,

)
def update_graph(href):
    fig = px.bar(df, x="Name", y="Count")
    params = parse_url_args(href)

    if "download" in params:
        print("Saving image")
        fig.write_image("image.png")
    return fig

It’s very strange that you can’t make a request to the server – is there any kind of middleware that filters this kind of “not-human” requests or maybe it's a feature in Dash enterprise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant