Development/Python

streamlit 사용해보기 (수정 예정)

juniz 2020. 6. 21. 12:02
반응형

Medium 에서 글을 보다가 전부터 보던 streamlit 관련된 글이 있어서 

다시 사용해본 후 쓰는 글입니다. 

 

streamlit 공식 페이지 

 

예전에 한번 쓰려 했으나, 당시에는 버그 등이 너무 많아서 아쉬웠지만 

이제는 안정화가 되었길 빌며 설치를 진행했습니다.

 

 

설치 

pip install streamlit

 

 

기본 실행

streamlit hello

 

Mapping, Animation, Plotting, Dataframe 등 다양한 데모를 확인 가능합니다. 

 

원하는 파일 실행 시 

streamlit run <file_name>

 

Example 

pip install opencv-python 

streamlit run https://raw.githubusercontent.com/streamlit/demo-self-driving/master/app.py

 

# stream.py

import streamlit as st
import numpy as np
import pandas as pd

st.title('My first app')

df = pd.DataFrame({
  'first column': [1, 2, 3, 4],
  'second column': [10, 20, 30, 40]
})


# Line Chart
chart_data = pd.DataFrame(
     np.random.randn(20, 3),
     columns=['a', 'b', 'c'])

st.line_chart(chart_data)

# Plot a map
map_data = pd.DataFrame(
    np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4],
    columns=['lat', 'lon'])

st.map(map_data)


if st.checkbox('Show dataframe'):
    chart_data = pd.DataFrame(
       np.random.randn(20, 3),
       columns=['a', 'b', 'c'])

    st.line_chart(chart_data)

#  Selectbox
# option = st.selectbox(
#     'Which number do you like best?',
#      df['first column'])
#
# 'You selected: ', option


#  Widget
option = st.sidebar.selectbox(
    'Which number do you like best?',
     df['first column'])

'You selected:', option

 

-- 추후 수정 예정-- 

반응형