gamcoh / st-card

Streamlit component for UI cards
https://pypi.org/project/streamlit-card/
MIT License
116 stars 19 forks source link

Allow empty backgroundImage property on cards in TSX #27

Closed ethanknights closed 5 months ago

ethanknights commented 7 months ago

If no image is used, as in this text_card:

import streamlit as st
from streamlit_card import card

st.title('Fix st_card')

image_card = card(
  title="Image card",
  text="Text & Image",
  image="http://placekitten.com/200/300",
)

text_card = card(
  title="No Image card",
  text="Just text"
)

This error is returned:

File "./venv/lib/python3.9/site-packages/streamlit/web/server/component_request_handler.py", line 51, in get
    with open(abspath, "rb") as file:
FileNotFoundError: [Errno 2] No such file or directory: './venv/lib/python3.9/site-packages/streamlit_card/frontend/build/null'

This PR addresses that error by setting the default backgroundImage property to none in TSX, if no image is provided in Python.

Tagging https://github.com/gamcoh/st-card/issues/25

gamcoh commented 7 months ago

Did you test it with multiple python versions?

ethanknights commented 7 months ago

Hi - Initially this worked with python version 3.9.16 and have now verified with 3.12.1 too:

$  streamlit run run.py

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://192.168.0.10:8501

  For better performance, install the Watchdog module:

  $ xcode-select --install
  $ pip install watchdog

^C  Stopping...

$ python --version
Python 3.12.1