cancel
Showing results for 
Search instead for 
Did you mean: 

Dash app and AppRouter

yannmiquel
Participant

Hi,

Has anyone succeed deploying a python application with Dash and the Approuter ?

The flask paths are fine but the dash paths don't work (they use callbacks functions)

Thanks

Yann

Accepted Solutions (0)

Answers (1)

Answers (1)

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert

Hi yannmiquel,

I did an experiment with dash and approuter and was able to run it. However, my app.py is very simple and based on the 1st step tutorial from their site. Therefore, I don't really see any callback requests being made from my app. Regardless, here is my xs-app.json
{
  "welcomeFile": "/dash/",
  "authenticationMethod": "none",
  "logout": {
    "logoutEndpoint": "/do/logout"
  },
  "routes": [
    {
      "source": "^/dash/(.*)$",
      "target": "/dash/$1",
      "authenticationType": "none",
      "csrfProtection": false,
      "destination": "dashy_api"
    }
  ]
}
and mta.yaml for you to compare:
ID: dashy
_schema-version: 3.2.0
version: 0.0.1
parameters:
  enable-parallel-deployments: true
modules:
  - name: dashApp
    type: nodejs
    path: approuter
    parameters:
      disk-quota: 512M
      memory: 512M
    requires:
      - name: dashy_api
        group: destinations
        properties:
          name: dashy_api
          url: '~{url}'
          forwardAuthToken: true

  - name: dashy
    type: python
    path: dashy
    parameters:
      disk-quota: 4G
      memory: 2G
      buildpacks:
      - https://github.com/cloudfoundry/python-buildpack
      stack: cflinuxfs3
    properties:
      BP_DEBUG: "True"
      DASH_URL_BASE_PATHNAME: '/dash/'
    provides:
      - name: dashy_api
        properties:
          url: '${default-url}'
I've changed the dash base URL to '/dash/' so it is the same as the one I am using on the approuter - by setting the environment DASH_URL_BASE_PATHNAME to '/dash/'. It might not be required. Instead you could just set the target for route "^/dash/(.*)$" like "/$1" in your xs-app.json. Notice the '/' in front of the '$1' - this means, use whatever comes after /dash/ and make a call to that destination without it. It would look something like:
{
  "welcomeFile": "/dash/",
  "authenticationMethod": "none",
  "logout": {
    "logoutEndpoint": "/do/logout"
  },
  "routes": [
    {
      "source": "^/dash/(.*)$",
      "target": "/$1",
      "authenticationType": "none",
      "csrfProtection": false,
      "destination": "dashy_api"
    }
  ]
}
If you could provide a more complex sample with callbacks I'll be glad to test it on my environment.BTW: I am using miniconda and python_buildpack to deploy with the following method:https://blogs.sap.com/2019/02/15/python-with-packages-that-depend-on-numpy-part-i/
Best regards,
Ivan
yannmiquel
Participant

Hi Ivan,

Your simple example has the 2 points jaming us : csrf protection and dash path. Now the app is on tracks. I will complete this comment asap with more details.

Thank you