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.1.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.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for streamlit_japanese_date_input-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e4bc35bd65d86216cdb3e04b4740d70a24dc6d925bb172ee47d1583ad4ae6ea7
MD5 9b6e47df5e492fac056e9afa6f955128
BLAKE2b-256 ca0214430a0f9359cacedac0faf06b1c0467242a64803f3b0e089ca9a7d8d9c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for streamlit_japanese_date_input-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c1e54cb37b1c35ff6d30b2dd6f7026ba70a1154177270afc28890d93da20b23a
MD5 f333a484a4d5ec98a30c8674e859e048
BLAKE2b-256 d75c933a1b321a4a07b70b5f052435cccd99601bcdc129b70d18be1c24490737

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