mirror of
https://github.com/aykhans/IMDBDataVisualization.git
synced 2025-04-21 09:03:27 +00:00
Added run.py; main: added radio button
This commit is contained in:
parent
733d155863
commit
54302b38d8
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
12
app/app.py
12
app/app.py
@ -1,3 +1,4 @@
|
|||||||
|
from matplotlib.pyplot import bar
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import plotly.express as px
|
import plotly.express as px
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
@ -26,11 +27,22 @@ class App():
|
|||||||
|
|
||||||
def createPieChart(self, data: pd.DataFrame, genres_type: str, selected_genres: List[str]):
|
def createPieChart(self, data: pd.DataFrame, genres_type: str, selected_genres: List[str]):
|
||||||
genres_count = self.getDataGenresCount(data, genres_type)
|
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()}).\
|
df = pd.DataFrame({'title': genres_count.keys(), 'count': genres_count.values()}).\
|
||||||
query('title == @selected_genres')
|
query('title == @selected_genres')
|
||||||
pie_chart = px.pie(df, names='title', values='count', title=genres_type + ' genres')
|
pie_chart = px.pie(df, names='title', values='count', title=genres_type + ' genres')
|
||||||
return pie_chart
|
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]:
|
def preprocessingData(self, upload_file: str) -> Optional[pd.DataFrame]:
|
||||||
if upload_file is not None:
|
if upload_file is not None:
|
||||||
data = pd.read_csv(upload_file)
|
data = pd.read_csv(upload_file)
|
||||||
|
39
app/main.py
39
app/main.py
@ -6,27 +6,42 @@ class Main():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.app = App(page_title='Dashboard', page_icon=':bar_chart:', layout='wide')
|
self.app = App(page_title='Dashboard', page_icon=':bar_chart:', layout='wide')
|
||||||
data = self.uploadFile()
|
data = self.uploadFile()
|
||||||
selected_genres = self.sideBar(data)
|
self.sideBar(data)
|
||||||
if data is not None:
|
|
||||||
self.app.st.plotly_chart(self.app.createPieChart(data, 'All', selected_genres))
|
self.addStyle()
|
||||||
# self.app.st.plotly_chart(self.app.createPieChart(data, 'Movie', selected_genres))
|
|
||||||
# self.app.st.plotly_chart(self.app.createPieChart(data, 'Series'))
|
|
||||||
|
|
||||||
def sideBar(self, data: pd.DataFrame):
|
def sideBar(self, data: pd.DataFrame):
|
||||||
data = self.app.getDataGenresCount(data, 'all')
|
data_genres_count = self.app.getDataGenresCount(data, 'all')
|
||||||
self.app.st.sidebar.header('Data by Genre:')
|
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(
|
data_genre_filter = self.app.st.sidebar.multiselect(
|
||||||
'Select Genre:',
|
'Select Genre:',
|
||||||
options = data.keys(),
|
options = data_genres_count.keys(),
|
||||||
default = data.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:
|
def uploadFile(self) -> pd.DataFrame:
|
||||||
uploaded_file = 'app\\WATCHLIST.csv' # app.st.file_uploader("Choose a file")
|
uploaded_file = 'app\\WATCHLIST.csv' # app.st.file_uploader("Choose a file")
|
||||||
data = self.app.preprocessingData(uploaded_file)
|
data = self.app.preprocessingData(uploaded_file)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def addStyle(self):
|
||||||
if __name__ == '__main__': Main()
|
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
4
app/run.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from main import Main
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__': Main()
|
Loading…
x
Reference in New Issue
Block a user