작성일자 : 2024-09-15
Ver 0.1.1
- Reference : API-Reference
- 실행시 streamlit run app.py
import streamlit as st
st.set_page_config(
page_title = "포켓몬 도감" #페이지 탭 이름
,page_icon = "./tutorial/images/monsterball.png" # 페이지 아이콘
)
st.title("streamlit 포켓몬 도감")
st.markdown("**포켓몬**을 하나씩 추가해서 도감을 채워보세요")
# 포켓몬 속성 Dictionary
type_emoji_dict = {
"노말": "⚪",
"격투": "✊",
"비행": "🕊",
"독": "☠️",
"땅": "🌋",
"바위": "🪨",
"벌레": "🐛",
"고스트": "👻",
"강철": "🤖",
"불꽃": "🔥",
"물": "💧",
"풀": "🍃",
"전기": "⚡",
"에스퍼": "🔮",
"얼음": "❄️",
"드래곤": "🐲",
"악": "😈",
"페어리": "🧚"
}
pokemons = [
{
"name": "피카츄",
"types": ["전기"],
"image_url": "https://storage.googleapis.com/firstpenguine-coding-school/pokemons/pikachu.webp"
},
{
"name": "누오",
"types": ["물", "땅"],
"image_url": "https://storage.googleapis.com/firstpenguine-coding-school/pokemons/nuo.webp",
},
{
"name": "갸라도스",
"types": ["물", "비행"],
"image_url": "https://storage.googleapis.com/firstpenguine-coding-school/pokemons/garados.webp",
},
{
"name": "개굴닌자",
"types": ["물", "악"],
"image_url": "https://storage.googleapis.com/firstpenguine-coding-school/pokemons/frogninja.webp"
},
{
"name": "루카리오",
"types": ["격투", "강철"],
"image_url": "https://storage.googleapis.com/firstpenguine-coding-school/pokemons/lukario.webp"
},
{
"name": "에이스번",
"types": ["불꽃"],
"image_url": "https://storage.googleapis.com/firstpenguine-coding-school/pokemons/acebun.webp"
},
]
# 창 사이즈를 줄였을 때도 숫자 순서대로 나오도록 변경
for i in range(0, len(pokemons), 3): #range(start : stop : step)
row_pokemons = pokemons[i:i+3]
cols = st.columns(3)
for j in range(len(row_pokemons)):
with cols[j]:
pokemon = row_pokemons[j]
with st.expander(label=f"**{i+j+1}. {pokemon['name']}**", expanded=True):
st.image(pokemon["image_url"])
#type에 매핑된 이모지 아이콘 추가
emoji_types = [f"{type_emoji_dict[x]} {x}" for x in pokemon["types"]]
#' / ' 으로 조인
st.text(" / ".join(emoji_types))