Streamlit UI 컴포넌트 소개
Streamlit UI 컴포넌트 소개
Streamlit
Streamlit UI 컴포넌트 소개
Streamlit은 Python으로 대화형 데이터 애플리케이션을 손쉽게 만들 수 있는 라이브러리입니다. 기본 UI 컴포넌트를 활용하여 사용자와 상호작용하고 정보를 시각화하는 방법을 알아보겠습니다.
1. 텍스트 표시하기
텍스트를 화면에 표시하는 방법은 여러 가지가 있습니다:
제목과 서브제목

import streamlit as st st.title('제목') st.header('헤더') st.subheader('서브헤더')일반 텍스트와 마크다운

st.text('일반 텍스트') st.markdown('**굵은 텍스트**')
2. 데이터 입력 받기
사용자 입력을 받는 컴포넌트는 다음과 같습니다:
텍스트 입력

user_input = st.text_input('이름 입력:') st.write('입력한 이름:', user_input)비밀번호 입력

password = st.text_input('비밀번호 입력:', type='password') st.write('입력한 비밀번호:', password)슬라이더

number = st.slider('숫자 선택:', 0, 100, 50) st.write('선택한 숫자:', number)드롭다운

option = st.selectbox('옵션 선택:', ['옵션 1', '옵션 2']) st.write('선택한 옵션:', option)
3. 버튼과 체크박스
버튼

if st.button('클릭하세요'): st.write('버튼이 클릭되었습니다!')체크박스

checkbox = st.checkbox('체크박스 선택') if checkbox: st.write('체크박스가 선택되었습니다!')라디오

option = st.radio( "좋아하는 색상을 선택하세요:", ('빨강', '파랑', '초록')) if option == '빨강': st.write("빨강을 선택하셨습니다.") elif option == '파랑': st.write("파랑을 선택하셨습니다.") else: st.write("초록을 선택하셨습니다.")멀티 선택 상자

options = st.multiselect( '좋아하는 스포츠를 선택하세요', ['축구', '야구', '농구', '배구']) st.write("선택한 스포츠:", options)
4. 데이터 시각화
Streamlit은 다양한 데이터 시각화 도구를 제공합니다:
라인 차트

import pandas as pd import numpy as np data = pd.DataFrame(np.random.randn(10, 2), columns=['A', 'B']) st.line_chart(data)바 차트

data = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6]}) st.bar_chart(data.set_index('x'))지도

locations = pd.DataFrame({ 'latitude': [37.76, 37.77], 'longitude': [-122.45, -122.46] }) st.map(locations)
5. 파일 업로드
파일 업로드를 위한 컴포넌트

uploaded_file = st.file_uploader('파일 업로드:', type=['csv', 'txt']) if uploaded_file is not None: data = pd.read_csv(uploaded_file) st.write(data)
6. 사이드바
사이드바를 활용한 입력 컴포넌트

st.sidebar.title('사이드바 제목') option = st.sidebar.selectbox('옵션 선택:', ['옵션 1', '옵션 2']) st.write('사이드바에서 선택한 옵션:', option)
<h3>카테고리 다른 글</h3>
| Date | Title | Author |
|---|---|---|
| Sep 21, 2024 | Streamlit 멀티 select 사용하기 | |
| Sep 21, 2024 | Streamlit selectbox를 사용하기 | |
| Sep 19, 2024 | Streamlit fragments 사용하기 | |
| Sep 19, 2024 | Streamlit form 사용하기 | |
| Sep 19, 2024 | Streamlit 데이터프레임 수정하기 | |
| Sep 19, 2024 | Streamlit fragments 사용하기 | |
| Sep 18, 2024 | Streamlit docker로 배포하기 | |
| Sep 18, 2024 | Streamlit 실시간 업데이트 사용하기 | |
| Sep 18, 2024 | Streamlit에서 다이얼로그 사용하기 | |
| Sep 18, 2024 | Streamlit의 유지보수와 디버깅 팁 | |
| Sep 17, 2024 | Streamlit cache_resource 사용하기 | |
| Sep 16, 2024 | Streamlit cache 사용하기 | |
| Sep 15, 2024 | Streamlit 데이터프레임 선택하기 | |
| Sep 14, 2024 | Streamlit 다중 page 구성하기 | |
| Sep 13, 2024 | Streamlit Session_state 사용하기 | |
| Sep 12, 2024 | Streamlit을 활용한 기본 시각화 도구 | |
| Sep 12, 2024 | Streamlit에 Plotly 차트 적용하기 | |
| Sep 11, 2024 | Streamlit에서 파일 업로드하기 | |
| Sep 11, 2024 | Streamlit에 SQLite 데이터베이스 적용 | |
| Sep 9, 2024 | Streamlit 사용 사례 | |
| Sep 9, 2024 | Streamlit 설치 및 환경설정 | |
| Sep 9, 2024 | Streamlit 애플리케이션 구조 이해 | |
| Sep 9, 2024 | Streamlit layout 설정하는 방법 | |
| Sep 8, 2024 | Streamlit이란 무엇인가요? | |
| Sep 6, 2024 | Streamlit Cloud로 앱 배포하기 |
No matching items