Announcing Dash Bio 1.0.0 🎉 : a one-stop-shop for bioinformatics and drug development visualizations.

Plotly Static Image Export in Production Environment

Hey all. I recently built an app that allows users to query and plot data. After plotting, the user will have the option of downloading static images of plots in a PowerPoint. This feature works perfectly on my localhost, but fails in a production environment. I have a feeling the issue is related to Kaleido not being properly installed, which at the current time I’m accomplishing by the following command in my Dockerfile:

RUN pip install -U kaleido

Any thoughts on this are appreciated. Below is a copy of the relevant code.

@ app.callback(
    Output('download', 'data'),
    Input('export-to-pp', 'n_clicks')
)
def display_graph(n):
    if n:
        prs = Presentation()
        slide_layout_index = 1
        inches_from_left = Inches(0)
        inches_from_top = Inches(1.1)

        fig=get_figure_function()

        blank_slide_layout = prs.slide_layouts[slide_layout_index]
        slide = prs.slides.add_slide(blank_slide_layout)

        in_memory_image = io.BytesIO()
        fig.write_image(in_memory_image, format='png', engine="kaleido")
    
        in_memory_image.seek(0)
        pic = slide.shapes.add_picture(in_memory_image, inches_from_left, inches_from_top)

        return send_bytes(lambda out: prs.save(out), filename='data.pptx')

I installed kaleido in the VM via the docker-command

#Installing python packages 
RUN pip3 install -r requirements.txt

with requirements.txt containing
[…]
kaleido==0.2.1
[…]

and it worked. In the server is Docker used for deployement?

Last part of the code employing kaleido:

[...]
format_image = 'svg'
img_bytes = img.to_image(format=f'{format_image}', engine="kaleido")
print(f'Download initiated.')
return dcc.send_bytes(img_bytes, filename=f'image.{format_image}')