Added run.py; main: added radio button

This commit is contained in:
Ayxan 2022-06-03 01:35:14 +04:00
parent 733d155863
commit 54302b38d8
4 changed files with 44 additions and 13 deletions

0
app/__init__.py Normal file
View File

View File

@ -1,3 +1,4 @@
from matplotlib.pyplot import bar
import pandas as pd
import plotly.express as px
from collections import Counter
@ -26,11 +27,22 @@ class App():
def createPieChart(self, data: pd.DataFrame, genres_type: str, selected_genres: List[str]):
genres_count = self.getDataGenresCount(data, genres_type)
if len(selected_genres) < 2: return None
df = pd.DataFrame({'title': genres_count.keys(), 'count': genres_count.values()}).\
query('title == @selected_genres')
pie_chart = px.pie(df, names='title', values='count', title=genres_type + ' genres')
return pie_chart
def createBarChart(self, data: pd.DataFrame, genres_type: str, selected_genres: List[str]):
genres_count = self.getDataGenresCount(data, genres_type)
if len(selected_genres) < 2: return None
genres_count_selected = {}
for i, j in genres_count.items():
if i in selected_genres:
genres_count_selected[i] = j
bar_chart = px.bar(x=genres_count_selected.keys(), y=genres_count_selected.values())
return bar_chart
def preprocessingData(self, upload_file: str) -> Optional[pd.DataFrame]:
if upload_file is not None:
data = pd.read_csv(upload_file)

View File

@ -6,27 +6,42 @@ class Main():
def __init__(self):
self.app = App(page_title='Dashboard', page_icon=':bar_chart:', layout='wide')
data = self.uploadFile()
selected_genres = self.sideBar(data)
if data is not None:
self.app.st.plotly_chart(self.app.createPieChart(data, 'All', selected_genres))
# self.app.st.plotly_chart(self.app.createPieChart(data, 'Movie', selected_genres))
# self.app.st.plotly_chart(self.app.createPieChart(data, 'Series'))
self.sideBar(data)
self.addStyle()
def sideBar(self, data: pd.DataFrame):
data = self.app.getDataGenresCount(data, 'all')
self.app.st.sidebar.header('Data by Genre:')
data_genres_count = self.app.getDataGenresCount(data, 'all')
genres_radio_btn = self.app.st.sidebar.radio('', ['All', 'Movie', 'Series'])
graphics_radio_btn = self.app.st.sidebar.radio('', ['Pie Chart', 'Bar Chart'])
# radio buttons vertical to horizontal
# self.app.st.write('<style>div.row-widget.stRadio > div{flex-direction:row;}</style>', unsafe_allow_html=True)
# self.app.st.sidebar.header('Data by Genre:')
data_genre_filter = self.app.st.sidebar.multiselect(
'Select Genre:',
options = data.keys(),
default = data.keys()
options = data_genres_count.keys(),
default = data_genres_count.keys()
)
return data_genre_filter
if data is not None:
try:
if graphics_radio_btn == 'Pie Chart':
self.app.st.plotly_chart(self.app.createPieChart(data, genres_radio_btn, data_genre_filter))
else:
self.app.st.plotly_chart(self.app.createBarChart(data, genres_radio_btn, data_genre_filter))
except: pass
def uploadFile(self) -> pd.DataFrame:
uploaded_file = 'app\\WATCHLIST.csv' # app.st.file_uploader("Choose a file")
data = self.app.preprocessingData(uploaded_file)
return data
if __name__ == '__main__': Main()
def addStyle(self):
hide_st_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
</style>
"""
self.app.st.markdown(hide_st_style, unsafe_allow_html=True)

4
app/run.py Normal file
View File

@ -0,0 +1,4 @@
from main import Main
if __name__ == '__main__': Main()