I tried using "Streamlit" which can do the Web only with Python

Introduction

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.

What is Streamlit

Streamlit is a library and service that allows you to write a front end (Web) with Python code.

This goal

Various versions

Installation

$ pip install streamlit

Play around with the tutorial

Hello App

$ streamlit hello

Will create a project. The browser will start and you can build the following demo site.

Screen Shot 2020-12-14 at 9.47.20.png

Creating a streamlit project

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

Make sure it is reflected interactively

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]
}))

Screen Recording 2020-12-14 at 10.48.50.gif

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 **!

Screen Shot 2020-12-14 at 11.23.50.png

Data acquisition from Connpass API

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! !!

aaa.gif

Limitations

Here is a summary of the restrictions I noticed while trying.

Deploy

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.

Screen Shot 2020-12-19 at 22.13.11.png

at the end

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

I tried using "Streamlit" which can do the Web only with Python
I tried using "Asciichart Py" which can draw a beautiful graph on the console with Python.
I tried web scraping with python.
I tried using the Python library from Ruby with PyCall
I tried "Streamlit" which turns the Python code into a web application as it is
vprof --I tried using the profiler for Python
I tried "differentiating" the image with Python + OpenCV
I tried using mecab with python2.7, ruby2.3, php7
I tried "binarizing" the image with Python + OpenCV
I tried using the Datetime module by Python
[Streamlit] I hate JavaScript, so I make a web application only with Python
I tried using the Python library "pykakasi" that can convert kanji to romaji.
I tried to solve the soma cube with python
I tried to solve the problem with Python Vol.1
I tried hitting the API with echonest's python client
I tried fp-growth with python
I tried scraping with Python
[Python] I tried using OpenPose
I tried gRPC with Python
I tried scraping with python
I tried to find the entropy of the image with python
I tried "gamma correction" of the image with Python + OpenCV
I tried to simulate how the infection spreads with Python
What you can do with the Python standard library statistics
I tried using the DS18B20 temperature sensor with Raspberry Pi
Miscellaneous notes that I tried using python for the matter
[Python] I tried collecting data using the API of wikipedia
I tried to divide the file into folders with Python
I tried using Thonny (Python / IDE)
I liked the tweet with python. ..
I tried running prolog with python 3.8.2.
I tried SMTP communication with Python
I tried using the checkio API
[Python] I tried using YOLO v3
Python | What you can do with Python
I tried scraping the ranking of Qiita Advent Calendar with Python
I tried to solve the ant book beginner's edition with python
I tried using the python module Kwant for quantum transport calculation
Consider what you can do with Python from the Qiita article
I tried to make a todo application using bottle with python
I tried to improve the efficiency of daily work with Python
I tried Diagram as Code (Diagrams) which can manage the configuration diagram code
What should I do with the Python directory structure after all?
I tried using Amazon SQS with django-celery
Behind the flyer: Using Docker with Python
I tried scraping Yahoo News with Python
I tried using Selenium with Headless chrome
I tried sending an email with python.
I tried using Bayesian Optimization in Python
Working with OpenStack using the Python SDK
I tried using UnityCloudBuild API from Python
Download files on the web with Python
I tried a functional language with Python
I tried recursion with Python ② (Fibonacci sequence)
Python: I tried the traveling salesman problem
I tried playing with the image with Pillow
I tried the Python Tornado Testing Framework
I tried using the BigQuery Storage API
#I tried something like Vlookup with Python # 2
What skills do I need to program with the FBX SDK Python?
[Python] I tried to visualize the night on the Galactic Railroad with WordCloud!