import asyncio
from panel.io.pyodide import init_doc, write_doc
init_doc()
import panel as pn
import pandas as pd
pn.extension('tabulator')
htmlM = "This is a demonstration dashboard for the GSU Book scraping project."
htmlM += " See the [Github repo](https://github.com/apwheele/GSU-books) for how data is"
htmlM += " generated and categorized. If you are interested in similar services, feel free"
htmlM += " [to get in touch](https://crimede-coder.com/contact)."
html_pane = pn.pane.Markdown(htmlM,width=450)
tf2024 = pd.read_csv('BookInfo_Fall2024.zip')
ts2025 = pd.read_csv('BookInfo_Spring2025.zip')
tf2024['Semester'] = '2024-Fall'
ts2025['Semester'] = '2025-Spring'
classes = pd.concat([tf2024,ts2025])
classes['ISBN'] = classes['ISBN'].astype(str).str.replace(".0","").str.replace("nan","")
classes.sort_values(by='MinVal',ascending=False,ignore_index=True,inplace=True)
classes['SECTION'] = classes['SECTION'].astype(str)
classes['COURSE'] = classes['COURSE'].astype(str)
classes_descript = {}
books_descript = {}
books = classes.groupby(['BOOKTITLE','ISBN','PUBLISHER'],as_index=False)[['enrollment','MinVal']].sum()
books['enrollment'] = books['enrollment'].astype(int)
books.sort_values(by='MinVal',ascending=False,ignore_index=True,inplace=True)
custom_style = {"text-align": "left"}
tab_classes = pn.widgets.Tabulator(classes, width=2000, layout='fit_columns',
pagination='local',page_size=10, header_filters=True, show_index=False,
theme='bootstrap5', theme_classes=['thead-dark', 'table-sm'])
tab_books = pn.widgets.Tabulator(books, layout='fit_columns',
pagination='local',page_size=10, header_filters=True, show_index=False,
theme='bootstrap5', theme_classes=['thead-dark', 'table-sm'])
main = pn.Tabs(('Classes', pn.Column(pn.Row(tab_classes), sizing_mode='stretch_both')),
('Books', pn.Column(pn.Row(tab_books), sizing_mode='stretch_both')),
('Info', pn.Column(pn.Row(html_pane), sizing_mode='stretch_both')))
pn.Row(main).servable();
from js import window
def run_after_load():
# Your JavaScript code here
window.alert("Page fully loaded!")
asyncio.ensure_future(write_doc());
window.onload = run_after_load