Dash.jl icon indicating copy to clipboard operation
Dash.jl copied to clipboard

Support for user-defined routes

Open rpkyle opened this issue 5 years ago • 3 comments

As described in https://dash.plot.ly/integrating-dash and seen in code examples posted to our community forum, Dash for Python permits app developers to leverage Flask support for adding new routes.

Dash.jl currently lacks this functionality; sample code in Dash for Python looks like this:

@app.callback(Output('my-link', 'href'), [Input('my-dropdown', 'value')])
def update_link(value):
    return '/dash/urlToDownload?value={}'.format(value)

@app.server.route('/dash/urlToDownload') 
def download_csv():
    value = flask.request.args.get('value')
    # create a dynamic csv or file here using `StringIO` 
    # (instead of writing to the file system)
    strIO = StringIO.StringIO()
    strIO.write('You have selected {}'.format(value)) 
    strIO.seek(0)    
    return send_file(strIO,
                     mimetype='text/csv',
                     attachment_filename='downloadFile.csv',
                     as_attachment=True)

User-defined routes are helpful generally, but particularly for documentation and applications where URL redirects are required.

rpkyle avatar May 24 '20 02:05 rpkyle

The HTTP package does not provide the "server" entity. The "server" in HTTP is a function that processes incoming requests. The most appropriate HTTP approach is to make make_handler part of the external API, then the user can make their own handler look like:

dash_handler = make_handler(app)
function my_handler(request::HTTP.Request)
     #do my staff
     ......
     #if my staff don't return anything
    HTTP.handle(dash_handler, request)
end

Theoretically, I can make the internal Dash router public, but then we need to include its documentation in the Dash documentation, because it is not part of HTTP. And this can confuse the user. And even in this case, providing the make_handler to the user should remain, because in addition to routing, the user may need to pre / or post processing of each request. For example for authorization

waralex avatar May 24 '20 07:05 waralex

The HTTP package does not provide the "server" entity. The "server" in HTTP is a function that processes incoming requests.

This isn’t a critical feature to implement now, just noting here for parity with Dash for Python.

rpkyle avatar May 24 '20 13:05 rpkyle

Support for this feature in Dash for R was added via https://github.com/plotly/dashR/pull/225; related improvements will be made in Dash for Python as described in https://github.com/plotly/dash/issues/1370.

rpkyle avatar Aug 23 '20 23:08 rpkyle