꾸준하고 즐겁게
Streamlit 사용해보기 본문
728x90
Streamlit에 대한 간략한 설명
Streamlit은 앱 프레임 워크이다.
시간대비 예쁘게 앱을 만들 수 있다는 점이 강점이다.
또한 아래에서 같이 확인해보겠지만, 사용법이 정말 쉽다.
Streamlit 기본 골격
import streamlit as st
def main():
pass
if __name__ == '__main__':
main()
streamlit의 기본 골격은 이렇다.
메인 함수에 코드를 작성해주면 된다.
앱을 실행하기 위해서는, streamlit run 파일명.py를 입력하면 된다.
기타 사용법
import streamlit as st
def main():
st.title("Bye Streamlit Project!!")
name = '바나나'
st.text("안녕하세요 저는 {}입니다".format(name))
st.header("안녕하세요")
st.markdown("# 큰글자")
st.markdown("## 중간글자")
st.markdown("### 작은글자")
st.markdown("#### 더작은글자")
st.markdown("##### 엄청작은글자")
st.subheader("서브헤더")
st.success("성공했을 때")
st.warning("사용자한테 경고 메세지를 남기고 싶을 때")
st.info("인포를 주고 싶을 때")
st.error("에러가 발생했다고 알리고 싶을 때")
if __name__ == '__main__':
main()
메세지를 출력하는 방법들도 다양하다.
앱을 실행해보면 이런 결과를 볼 수 있다.
앱 사용자와 상호작용을 할 수 있는 버튼이나 슬라이더를 만들 수도 있다.
import streamlit as st
def main():
now = 29
year = st.slider('년수', 1, 100)
age = now + year
st.write("{}년 후, {}세".format(year, age))
if __name__ == '__main__':
main()
당장 생각나는 예시로 간단하게 슬라이더를 만들어보았다.
여러 버튼을 포함해 스트림릿에 대해 더 알아보고 싶다면 레퍼런스를 참조하면 된다.
docs.streamlit.io/en/stable/api.html
더보기
삼고빔...
개발자로 행복한 삶을 살았길...
728x90