littlemermaid___
littlemermaid___11mo ago

mo.image() not working with local files

I'm trying to insert an image using mo.image(src="./imgs/mab_1.png") , it shows a broken image instead of the image. I've also tried the with open("logo.png", "rb") as file: mo.image(src=file) approach - nothing turns up (Changed the string to point to my image. I'm not seeing any errors to work with. I've tried just opening the image directly and that works so i've not messed up the paths. Any suggestions?
4 Replies
Akshay
Akshay11mo ago
@littlemermaid___ , thanks for providing the output of marimo env. I can reproduce your issue — mo.image() isn't working with local images for me either. Thanks for letting us know, looking into it. Oops, spoke too soon. The file has to be opened in binary mode. This works for me:
with open("path/to/image.png", "rb") as f:
img = mo.image(src=f)
img
with open("path/to/image.png", "rb") as f:
img = mo.image(src=f)
img
The img has to be output in the last expression of the cell for it to show up. I can update the docs to be clearer about this. If you paste the above in a cell, does it work?
Akshay
Akshay11mo ago
For example:
No description
littlemermaid___
littlemermaid___OP11mo ago
Ah ok that makes sense! Thanks for the help works a charm 👎 👍 rather!
Akshay
Akshay11mo ago
Yep no problem! In the latest release you should also be able to pass a path to a local file