X11 forwarding with plotly on AWS EC2


I have an AWS EC2 instance with no graphics capabilities in the CPU so with other visual solutions like matplotlib I tunnel the image through X11 back to my local machine (using Putty configured with X11).

I would like to do the same for plotly as it has better mapping capabilities but it is not clear how to do this. I did read at the link below that Xvfb is used if x11 display server is not available.

I haven’t (yet) installed an X11 display server and I’m also aware that orca is no longer the recommended way since plotly 4.9 was released for static image export (Orca Management) so I’m not sure if I want to go to the effort to get that working. At the moment, I use write_image but this is a bit clumsy as I then have to retrieve it off the AWS instance down to my local machine every time, instead of using X11 forwarding in my Python script. Also, the hover data is not viewable in the downloaded plot.

Any help appreciated.

#!/usr/bin/env python3
import pandas as pd

us_cities = pd.read_csv(“https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv”)

import plotly.express as px

fig = px.scatter_mapbox(us_cities, lat = “lat”, lon = “lon”, hover_name = “City”, hover_data = [“State”, “Population”], color_discrete_sequence = [“fuchsia”], zoom = 3, height = 300)
fig.update_layout(mapbox_style = “open-street-map”)
fig.update_layout(margin = {“r”:0, “t”:0, “l”:0, “b”:0})
fig.write_image(‘plotOpen.png’, engine = ‘kaleido’)