streamlit0620



カレンダー
```python
import streamlit as st
from streamlit_calendar import calendar

def main():

    col1, col2 = st.columns([1, 2])

    with col1:
        pass

    with col2:
        # Create a dropdown to select calendar view
        view_mode = st.selectbox("Select Calendar View", ["月間表示", "時間ごとの表示", "リスト表示", "年間表示"])

        # Define calendar options based on selected view mode
        if view_mode == "月間表示":
            calendar_options = {
                # "editable": True,
                "selectable": True,
                "headerToolbar": {
                    "left": "",
                    "center": "title",
                    "right": "prev,next today",
                },
                "initialView": "dayGridMonth",
            }
        elif view_mode == "時間ごとの表示":
            calendar_options = {
                "editable": True,
                "selectable": True,
                "headerToolbar": {
                    "left": "timeGridDay,timeGridWeek",
                    "center": "title",
                    "right": "prev,next today",
                },
                "initialView": "timeGridWeek",
                "slotMinTime": "06:00:00",
                "slotMaxTime": "18:00:00",
            }
        elif view_mode == "リスト表示":
            calendar_options = {
                "editable": True,
                "selectable": True,
                "headerToolbar": {
                    "left": "",
                    "center": "title",
                    "right": "prev,next today",
                },
                "initialView": "listMonth",
                "slotMinTime": "06:00:00",
                "slotMaxTime": "18:00:00",
            }
        elif view_mode == "年間表示":
            calendar_options = {
                "editable": True,
                "selectable": True,
                "headerToolbar": {
                    "left": "",
                    "center": "title",
                    "right": "prev,next today",
                },
                "initialView": "multiMonthYear",
                "slotMinTime": "06:00:00",
                "slotMaxTime": "18:00:00",
            }

        calendar_events = [
            {
                "title": "Event 1",
                "start": "2024-07-01T08:30:00",
                "end": "2024-07-04T10:30:00",
                "backgroundColor":"#FF6C6C",
                "borderColor":"#FF6C6C",
            },
            {
                "title": "Event 2",
                "start": "2024-07-13T07:30:00",
                "end": "2024-07-17T10:30:00",
                "backgroundColor":"#3DD56D",
                "borderColor":"#3DD56D",
            },
            {
                "title": "Event 3",
                "start": "2024-07-30T10:40:00",
                "end": "2024-07-31T12:30:00",
            },
            {
                "title": "Event 4",
                "start": "2024-07-30",
                "end": "2024-07-30",
            }
        ]

        # Render calendar based on selected options
        calendar(events=calendar_events, options=calendar_options)

if __name__ == '__main__':
    main()

```


excelでダウンロード
```python
import streamlit as st
import pandas as pd
from io import BytesIO

# サンプルのDataFrameを作成
df = pd.DataFrame({
    'Column1': [1, 2, 3, 4],
    'Column2': ['A', 'B', 'C', 'D']
})
edited_df = st.data_editor(df, num_rows="dynamic")

# Excel形式でダウンロードするボタン
def download_excel(data):
    output = BytesIO()
    with pd.ExcelWriter(output, engine='openpyxl') as writer:
        data.to_excel(writer, sheet_name='Sheet1', index=False)
    excel_data = output.getvalue()
    return excel_data

st.download_button(
    label='ここをクリックしてExcelファイルをダウンロード',
    data= download_excel(edited_df),
    file_name='data.xlsx',
    mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)

```


カンバン
```python
import streamlit as st
import pandas as pd

# セッション状態の初期化
if 'tasks' not in st.session_state:
    st.session_state.tasks = {
        'To Do': [],
        'In Progress': [],
        'Done': []
    }

# 新しいタスクを追加する関数
def add_task():
    task = st.session_state.new_task
    if task:
        st.session_state.tasks['To Do'].append(task)
        st.session_state.new_task = ''

# タスクを移動する関数
def move_task(task, from_column, to_column):
    st.session_state.tasks[from_column].remove(task)
    st.session_state.tasks[to_column].append(task)

# タイトル
st.title("カンバンボード")

# 新しいタスクを入力するテキストボックス
st.text_input("新しいタスクを追加", key='new_task')
st.button("追加", on_click=add_task)

# カンバンボードの表示
columns = st.columns(3)
statuses = ['To Do', 'In Progress', 'Done']

for i, status in enumerate(statuses):
    with columns[i]:
        st.header(status)
        for task in st.session_state.tasks[status]:
            st.write(task)
            if status != 'To Do':
                st.button("To Doに移動", key=f"{task}_to_todo", on_click=move_task, args=(task, status, 'To Do'))
            if status != 'In Progress':
                st.button("In Progressに移動", key=f"{task}_to_inprogress", on_click=move_task, args=(task, status, 'In Progress'))
            if status != 'Done':
                st.button("Doneに移動", key=f"{task}_to_done", on_click=move_task, args=(task, status, 'Done'))

```