Sun.El Data Analysis

[Streamlit] Python 데이터 분석을 웹/앱으로 만들기 본문

카테고리 없음

[Streamlit] Python 데이터 분석을 웹/앱으로 만들기

Sun.El 2023. 8. 2. 23:57
728x90

Python으로 데이터 분석을 위한 웹앱을 만들어주는 라이브러리
모델 배포, 그래프 시각화 등 웹어플리케이션을 배포할 수 있는 패키지
데이터/ML 앱을 만들기 위한 가장 빠른 방법

 

1. Streamlit의 장점 및 한계

  • 장점
백엔드 개발이나 HTTP 요청이 필요 없음
다양한 입력 위젯 (컴포넌트) 제공
간단히 배포 가능
빠르고 쉽게 배울 수 있음

 

  • 단점
Django, Flask, 등과 같은 웹 프레임워크를 대체하지는 못함
기본적으로 제공되는 기능을 초월하기가 어려움
실행이 효율적이지는 않음

 

2. 개발환경 설정

  • Anaconda 설치
https://www.anaconda.com

 

  • Visual Studio Code 설치
https://code.visualstudio.com

 

  • Streamlit 설치 및 참고
https://streamlit.io
pip install streamlit
  Docs --> Get started --> Installation
  Docs --> API reference

 

3. 가상환경 만들기

  • 가상환경을 만들면 프로젝트 별로 필요한 버전의 파이썬과 라이브러리를 설치할 수 있음
  • base 환경으로 가기
(STR) C:\Users\Streamlit> conda deactivate
(base) C:\Users\Streamlit>

 

  •  가상환경 목록 보기
conda env list

 

  • 가상환경 STR 만들기
(base) C:\Users\Streamlit> conda create –n STR python=3.9.13
(base) C:\Users\Streamlit> conda activate STR
(STR) C:\Users\Streamlit>

 

  • 필요한 라이브러리들을 일괄 설치
(STR) C:\Users\UStreamlit> pip install –r ready.txt

 

  • 가상환경 삭제
(base) C:\Users\Streamlit> conda env remove –n STR

 

  • 가상환경 STR에 Streamlit 설치하기
(STR) C:\Users \USER>pip install streamlit

 

  • 앱 실행하기
(STR) C:\Users \Streamlit> streamlit run myApp.py

 

4. 앱 배포

  • Streamlit cloud를 통해서 간편하게 앱을 배포할 수 있음
  • Github을 통해 설치됨
  • 앱 배포 순서
1. 가상환경 터미널에서 다음을 실행해서 설치가 필요한 라이브러리 목록 을 만든다
• pip freeze > ready.txt • 주의: 혹시 라이브러리 목록에 certifi @ file:///private ~~~ 가 있으면 삭제한다.
• pip freeze > ready.txt • 주의: 혹시 라이브러리 목록에 certifi @ file:///private ~~~ 가 있으면 삭제한다.

2. www.github.com으로 가서 계정을 열고 로그인 한다.
• 왼쪽 상단에서 [Create repository] 버튼을 클릭하고 새로운 repository를 만든다(public)

3. 새롭게 만들어진 repository에서 [Add file]을 클릭하고 "Upload files" 를 선택한다.


4. 앱 파일들을 drag & drop 하고 아래 [Commit changes]를 클릭한다.


5. share.streamlit.io로 가서 [Continue with GitHub]를 선택하고 들어간다.(처음이면 set up 절차가 있으니 따라서 한다.)


6. 다음 화면에서 [New app] 버튼을 누르고 GitHub repository와의 연결을 승인한다


7. 설정을 채워 넣고 [Deploy!] 버튼을 눌러서 완료한다.


8. 잠시의 기다림 이후 앱 배포가 완료된다. 앱의 URL을 기억해 둔다.

    예). https://encore-streamlitdata-app01-wqhf5x.streamlit.app/

 

5. 참고사이트

 

Streamlit • A faster way to build and share data apps

Streamlit is an open-source app framework for Machine Learning and Data Science teams. Create beautiful web apps in minutes.

streamlit.io

 

App Gallery • Streamlit

Streamlit is an open-source app framework for Machine Learning and Data Science teams. Create beautiful web apps in minutes.

streamlit.io

 

Zarathu Blog - Python Streamlit 패키지를 이용한 대시보드 만들기

https://docs.streamlit.io/library/api-reference 를 바탕으로 정리한 글입니다. 2023년 2월 기준) streamlit version 1.17.0 을 기준으로 작성하였습니다. Streamlit 소개 언제 스트림릿을 사용해야할지 스트림릿이 타

blog.zarathu.com

 

Streamlit vs. Dash vs. Shiny vs. Voila vs. Flask vs. Jupyter

Comparing data dashboarding tools and frameworks

towardsdatascience.com

 

6. 붓꽃 데이터 분석 결과물 공유