Skip to main content

Streamlit component for date input with Japanese localization

Project description

Japanese Date Input Component for Streamlit

日本語表記に対応したStreamlit用のdate inputコンポーネントです。 サードパーティコンポーネントとして実装する場合、制限事項があるため、基本的にはst.date_inputの使用を推奨します。

特徴

  • 📅 日本語の曜日表示(月、火、水、木、金、土、日)
  • 📆 日本語の月表示(1月、2月、...、12月)

インストール

pip install streamlit-japanese-date-input

使い方

基本的な使用例

以下のスクリプトを実行することで、アプリケーションの諸々の挙動を確認することができます。 以下のgifのような挙動になります。

streamlit run example.py

demonstration

パラメータ

  • label (str): 入力フィールドのラベル
  • value (date/datetime/str, optional): 初期値
  • min_value (date/datetime/str, optional): 選択可能な最小日付
  • max_value (date/datetime/str, optional): 選択可能な最大日付
  • format (str): 日付フォーマット(デフォルト: "YYYY/MM/DD")
  • disabled (bool): 入力を無効化するかどうか
  • width (str or int): ウィジェットの幅("stretch"または固定ピクセル値)
  • sidebar_mode (bool): サイドバーでの表示に最適化するかどうか(デフォルト: False)
  • key (str, optional): コンポーネントの一意のキー

サイドバーでの使用について

Streamlitのカスタムコンポーネントは独立したiframe内で動作するため、Streamlitのサイドバーの中に、このコンポーネントを配置していることを自動的に検出することができません。 そのため、サイドバーで使用する場合はsidebar_mode=Trueを明示的に指定する必要があります。

# サイドバーでの使用例
with st.sidebar:
    selected_date = japanese_date_input(
        "日付を選択",
        sidebar_mode=True  # サイドバーでは必ずTrueに設定
    )

sidebar_mode=Trueを設定すると、背景色が白色・テキストが黒色となり、サイドバーのデザインに調和します

制限事項

1. iframe内での表示制約

カスタムコンポーネントは iframe 内で動作するため、カレンダーを親ウィンドウの上に重ねて表示する「ダイアログ形式」は実現できません。 以下の制限があります。

  • 狭いコンテナやサイドバーではカレンダーが見切れる
  • iframe を超えて表示することはできない
  • 高さを動的に調整しても限界がある

一方、st.date_input は iframe ではなく Streamlit 本体のウィジェットのため、こうした制約がなく常に正しく表示されます。

2. サイドバーや狭いレイアウトでの自動検出不可

カスタムコンポーネントは親ウィンドウのDOMを参照できないため、 サイドバーで使う場合は手動でsidebar_mode=Trueを設定する必要があります。 これにより、背景色や文字色の調整が行えます。

3. メンテナンスや互換性の面

カスタムコンポーネントは React と Streamlit Components API に依存するため、Streamlit のアップデートやテーマ変更により動作が壊れる可能性があります。 また、iframe の制約を回避するために複雑な実装や高さ調整が必要になる場合があります。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_japanese_date_input-0.1.5.tar.gz (178.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_japanese_date_input-0.1.5-py3-none-any.whl (177.1 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_japanese_date_input-0.1.5.tar.gz.

File metadata

File hashes

Hashes for streamlit_japanese_date_input-0.1.5.tar.gz
Algorithm Hash digest
SHA256 5f94a01a3448decc4a59711782857d1aa4dbea02845e4b2244dc60de215ed7dd
MD5 ce7e5127d7dfa330a1bda3b0e6ec3526
BLAKE2b-256 5613d955c3b1cfe757b9c5907ef4f89370720a0c4ddc03d21564a536f29e84dd

See more details on using hashes here.

File details

Details for the file streamlit_japanese_date_input-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_japanese_date_input-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 250fa2485c3778308875f4c25faad80e716570421daf5e10a4b06691bec8118a
MD5 d530c91036be154bddc94827dd6c09d8
BLAKE2b-256 5afe51adb1a3f70eea5b5c5ca68b313fad1e42c6474666592755a24efee9382e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page