0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Streamlitの使い方(超入門)

Posted at

Webブラウザを利用したファイル選択ダイアログボックスの作り方

PythonのStreamlitというパッケージを用いて,Webブラウザでファイル選択するダイアログボックスを作成する例を示します.

Select_File.py
import streamlit as st
import pandas as pd

st.title("Excel File Uploader")

# ファイルアップローダーでExcelファイルを選択
uploaded_files = st.file_uploader("Choose Excel files", accept_multiple_files=True, type="xlsx")

if uploaded_files:
    file_names = [file.name for file in uploaded_files]
    
    # プルダウンメニューでファイル名を選択
    selected_file_name = st.selectbox("Select a file", file_names)
    
    # 選択したファイルを読み込む
    for file in uploaded_files:
        if file.name == selected_file_name:
            df = pd.read_excel(file)
            st.write("File name:", selected_file_name)
            st.dataframe(df)

このPythonスクリプトの実行方法

1.コマンドプロンプトを管理者で実行
2.以下のプロンプトを入力してリターンキーを押す
    streamlit run Select_file.py
すると規定のブラウザが立ち上がる.
image.png

ブラウザ上で,ファイル選択のダイアログボックスGUIが出来上がる.
image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?