Load a jpg into a server module from assets, possible?

Hi

In my app I create a matplotlib plot which works nicely in Anvil :+1:. I would like to add a logo to the plot (using ax.imshow(im, ...)), which is a small jpg file. The jpg file should be stored in the Anvil app.

I thought of storing the jpg file in the theme folder (uploaded into assets) such that I could access it from my server module using:

im = matplotlib.image.imread('_/theme/logo.png')

However, this does not work :cry:.

Any idea how I could manage the access to the jpg file?

regards,

Vinz

Hello,

Please see this post which details getting at the assets (or instead storing the file in DataTables):

Hi @alcampopiano

Thanks for directing me to this post!

Vinz

1 Like

Hi

The following lines did the trick with the matplotlib graph:

contents =anvil.server.get_app_origin() + "/_/theme/logo_small.png"
im = plt.imread(contents, format='png')
fig.figimage(im, xo=3950,yo=360,resize=False)

I had problems doing the same with the image stored in a Data Table. But I am actually happy with the solution I have now.

Kind regards,

Vinz

2 Likes