Search code examples
pythonplotly

Plotly express graph not showing in containerized dash application deployed to the cloud


I am running a Python Dash application deployed in serverless container, the app work well except when I add Plotly.express figure then the page won't load or the app will restart .. I checked the logs and got the following error

ERROR RequestID: ffecdb8a-4088-41fc-8fd0-1e2b45955412 Code: 502 Message: Error during function invocation

it seems that the problem is in Plotly.express way of creating the visual since it uses temp server to create interactive graph (the same function work without any error if the return body does not contain plotly.express figure)

Does anyone have any ideas how to fix this?


Solution

  • The problem was in Plotly js response file size. it seems that most cloud providers have technical limitations due to architectural features. one of the common limits when working with serverless containers is maximum size of the container's HTTP request and response, in my case the limit was 3.5 MB . and the javascript plolty response was 3.6 MB !!! So the solution is to define alternative plotly js bundle instead of the default one .. like this:

    app = dash.Dash(__name__,external_scripts=['https://cdn.plot.ly/plotly-basic-2.12.1.min.js'])
    

    there are more bundles to check and choose the optimal one for the application: https://github.com/plotly/plotly.js/blob/master/dist/README.md