Hi,
How would I display an image from a URL in python shiny. I am trying to build where a user can supply a url of an image to display it within my app
I tried the approach of downloading the image directly from the url in the app below, as inspired by the documentation but the app gets reloaded constantly due to watchfiles so I am wondering if there is a better approach rather than turning off watch files
Thanks
Iain
Thanks
Iain
from shiny import App, Inputs, Outputs, Session, render, ui
from shiny.types import ImgData
import requests
app_ui = ui.page_fluid(ui.output_image("image"))
def server(input: Inputs, output: Outputs, session: Session):
@output
@render.image
def image():
from pathlib import Path
img_url = "https://sample-videos.com/img/Sample-png-image-100kb.png"
response = requests.get(img_url)
if response.status_code:
fp = open('my_image.png', 'wb')
fp.write(response.content)
fp.close()
dir = Path(__file__).resolve().parent
img: ImgData = {"src": str(dir / "my_image.png"), "width": "100px"}
return img
app = App(app_ui, server)