Skip to content

Dash for R API does not currently allow user-defined routes #131

Closed

Description

@rpkyle

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 for R currently lacks this functionality, so Dash for Python code 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)

currently has no direct counterpart on the R side. We should expose the ability for application developers to define new routes within the Dash for R API. One possible option is through the use of fiery plugins. e.g. a server_route method could be added which exposes the ability to add plugins with new route handlers:

plugin <- list(
    on_attach = function(server) {
     router <- server$plugins$request_routr
     route <- Route$new()
     route$add_handler('all', '*', function(request, response, arg_list, ...) {
       message('Hello')
       TRUE
    })
    router$add_route(route, 1)
    },
  name = 'Hello_plugin',
  require = 'request_routr'
)

Thanks to @CanerIrfanoglu for raising this issue initially.

Activity

  1. self-assigned this
    on Sep 24, 2019
  2. added
    parityModifications to improve parity across Dash implementations
    on Sep 24, 2019
  3. changed the title [-]Dash for R API does not currently allow used-defined routes[/-] [+]Dash for R API does not currently allow user-defined routes[/+] on Sep 24, 2019
  4. added this to the Dash v1.5.0 milestone on Sep 24, 2019
  5. 10 remaining items

  6. rpkyle commented on Aug 28, 2020

    @rpkyle
    ContributorAuthor

    Closed by #225.

  7. reopened this on Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featureparityModifications to improve parity across Dash implementationssize: 3

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions