This article is JSL (Japan System Giken) Advent Calendar 2020 --Qiita 20th day article.
It is an annual anniversary commemoration. : tada: Even at this age, I'm still wondering.
I haven't been working on development for a long time, so I was worried about what to write.
The other day, I will talk about using Streamlit
, which nikkie introduced at the" Everyone's Python Study Group "that I participated in, because it looks interesting.
Streamlit is a library and service that allows you to write a front end (Web) with Python code.
$ pip install streamlit
Hello App
$ streamlit hello
Will create a project. The browser will start and you can build the following demo site.
Follow the tutorial and import streamlit
and various libraries as follows
streamlit run [filename]
will start the browser.
import streamlit as st
import numpy as np
import pandas as pd
Just pass the title and the Pandas DataFrame like this and the browser will be updated interactively! ..
st.title('My first app')
st.write("Here's our first attempt at using data to create a table:")
st.write(pd.DataFrame({
'first column': [1, 2, 3, 4],
'second column': [10, 20, 30, 40]
}))
Magic command
In addition to the write
function, there is a function called Magic commands
, and it seems that the behavior is the same as the write
function just by writing a variable as shown below.
df = pd.DataFrame({
'first column': [1, 2, 3, 4],
'second column': [110, 200, 300, 400]
})
df
x=10
x
Like this, it will be generated with Gorigori ** Python only **!
It seems that you can do various things just by playing with the tutorial, so I got the data of "GEEKLAB.NAGANO" operated by our company from "Connpass API" and displayed the event information.
geeklab_eventlist.py
import streamlit as st
import pandas as pd
import requests, io
from datetime import datetime, date, timedelta
from dateutil.relativedelta import relativedelta
from PIL import Image
st.title('Geek Lab Event List')
image_url = 'https://connpass-tokyo.s3.amazonaws.com/thumbs/72/9d/729d521ab794e98b4427e9040e8f2fe9.png'
image = Image.open(io.BytesIO(requests.get(image_url).content))
st.image(image, use_column_width=True)
today = datetime.today()
startdate = datetime.strftime(today, '%Y%m')
enddate = "201402"
target_date_set = ['All cases']
target_date_set.append(startdate)
while startdate > enddate:
dt = datetime.strptime(startdate, '%Y%m') - relativedelta(months=1)
startdate = dt.strftime("%Y%m")
target_date_set.append(startdate)
yyyymm = st.selectbox(
'Event date',
target_date_set
)
count = st.slider('Number of acquisitions', 0, 100, 10)
keyword = st.text_input('keyword', '')
r = requests.get(f'https://connpass.com/api/v1/event/?series_id=2591&count={count}&ym={yyyymm}&keyword={keyword}')
titles = []
event_date_set = []
participants = []
owners_name = []
for e in r.json()["events"]:
titles.append(e["title"])
dt = datetime.fromisoformat(e["started_at"])
event_date_set.append(datetime.strftime(dt, '%Y/%m/%d'))
participants.append(e["accepted"])
owners_name.append(e["owner_display_name"])
df = pd.DataFrame({
'title': titles,
'event date': event_date_set,
'Number of participants': participants,
'Administrator': owners_name
})
df.style.set_properties(**{'text-align': 'center'})
df
With just this much Python code, it's amazing what you can do so far! !!
Here is a summary of the restrictions I noticed while trying.
selectbox
You can deploy it by linking the GitHub repository including requirements.txt
to https://share.streamlit.io/
.
It seems that you will be notified of invitation emails on a weekly basis, and it will take some time before it becomes available.
When you receive the invitation email, just enter the necessary information and like this Will deploy to.
After attending the study session after a long time, I tried to touch Streamlit
, but when I tried using it, I came across a library that seems to be " fun ", " amazing !! ". Although there are some restrictions, I thought it was a good mechanism to quickly see if the data was visible.
Above all, it is good to be able to write in ** Python only **.
It's hard to keep catching up individually, so I reaffirmed the importance of attending study sessions on a regular basis! !! .. I would like to take this opportunity to thank nikkie! !!
Recommended Posts