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.4.tar.gz (6.0 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.4-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for streamlit_japanese_date_input-0.1.4.tar.gz
Algorithm Hash digest
SHA256 6a63a6bcd2b7d6baed2f95e6d0294db1348d23368cfaa586fc9db242c304cd26
MD5 f53a7ce15092dcdab9ea34cb65f03af4
BLAKE2b-256 80c32565fd3050c0a0bae7afbd2cf78af911f37fce10dd7ab2169cd3c4985201

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for streamlit_japanese_date_input-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ec7f8ef5d7982f0d15522e3a2bd2a4235a6b26f022f92e3457a9e97f86611dd9
MD5 85a2c8007d6f51defcfea6cb08a20176
BLAKE2b-256 cf3a72b65b2a9bb84fad6147c265c65bccc3e6340bf1fe6619c89f0e3129d4ef

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