| from cProfile import label |
| import select |
| from shiny import App, render, reactive,ui |
|
|
| from shiny.ui import h2, tags |
| |
| import pandas as pd |
| import io |
| import csv |
| import asyncio |
| |
| from matplotlib import pyplot as plt |
| from supp import * |
|
|
| curr_df = get_survey_responses() |
|
|
|
|
|
|
|
|
| app_ui = ui.page_fluid( |
| ui.panel_title("Login"), |
| ui.row( |
| ui.input_text("username","Username:",placeholder="username"), |
| ui.input_password("password","Password:"), |
| ui.input_action_button("submit","Log in/Log out",width='200px'), |
| ui.input_action_button("show_guide","Guideline",width='200px'), |
|
|
| ), |
|
|
| ui.row( |
| ui.column( |
| 6, |
| ui.panel_well( |
| ui.output_text("out_text1"), |
| |
| ) |
| |
| ) |
| ), |
|
|
| ) |
|
|
|
|
| def server(input, output, session): |
| login_status = -1 |
|
|
|
|
|
|
| @output |
| @render.text |
| def out_text1(): |
| return "Current Responses:" |
|
|
|
|
| @output |
| @render.ui |
| @reactive.Effect |
| @reactive.event(input.submit) |
| def submit(): |
| |
| nonlocal login_status |
| |
| if login_status==-1: |
| username = input.username() |
| password = str(input.password()) |
| correct_or_not = checkpassword(username,password) |
| if correct_or_not ==1: |
| ui.remove_ui(selector="div:has(> #username)") |
| ui.remove_ui(selector="div:has(> #password)") |
| login_status=1 |
| |
| |
| ui.insert_ui( |
| ui.download_button("save_result","Download Table",width='150px'), |
| selector="#out_text1", |
| where="afterEnd" |
| ) |
| ui.insert_ui( |
| ui.output_plot("sec_plot1"), |
| selector="#out_text1", |
| where="afterEnd" |
| ) |
| ui.insert_ui( |
| ui.output_plot("sec_plot2"), |
| selector="#out_text1", |
| where="afterEnd" |
| ) |
| """ |
| """ |
| |
| elif login_status ==1: |
| ui.remove_ui(selector="div:has(> #sec_plot1") |
| ui.remove_ui(selector="div:has(> #sec_plot2)") |
| |
| ui.remove_ui(selector="div:has(> #save_result)") |
| ui.insert_ui( |
| ui.input_text("username","Username:",placeholder="username"), |
| selector="#submit", |
| where="beforeBegin", |
| |
| ) |
| ui.insert_ui( |
| ui.input_password("password","Password"), |
| selector="#submit", |
| where="beforeBegin", |
| ) |
| ui.insert_ui( |
| ui.row( |
| ui.column( |
| 5, |
| ui.panel_well( |
| ui.output_text("out_text1"), |
| ) |
| ) |
| ), |
| selector="#show_guide", |
| where="afterend" |
| ) |
| |
| """ |
| |
| ui.insert_ui( |
| ui.output_text("out_text1"), |
| selector ="#Main Page", |
| where="afterEnd" |
| |
| ) |
| """ |
| """ |
| |
| |
| ui.insert_ui( |
| ui.output_text("text_c1"), |
| selector ="#submit", |
| where ="afterEnd", |
| ) |
| """ |
|
|
| |
|
|
|
|
| login_status=-1 |
|
|
|
|
|
|
| @output |
| @render.plot |
| def sec_plot1(): |
| nonlocal login_status |
|
|
| from matplotlib import pyplot as plt |
| num1 = get_response_data(curr_df,"Principal","INFO_1","INFO_5","INFO_6") |
| print("current status is "+str(login_status)) |
| |
| fig,ax = plt.subplots() |
|
|
| finished_resp = 0 |
| for k,v in num1.items(): |
| finished_resp+=len(v) |
| unfinish = get_totalsize()-finished_resp |
| c1 = "Principal, Response: "+str(finished_resp)+", Not Response: "+str(unfinish) |
| ax.pie([finished_resp,unfinish],labels = ["Finished","Not Finished"],autopct = '%2.2f%%') |
| ax.set_title(c1) |
|
|
| return fig |
|
|
|
|
| @output |
| @render.plot |
| def sec_plot2(): |
| from matplotlib import pyplot as plt |
| num1 = get_response_data(curr_df,"Educator","INFO_1","INFO_5","INFO_6") |
| finished_resp = 0 |
| for k,v in num1.items(): |
| finished_resp+=len(v) |
| unfinish = get_totalsize()-finished_resp |
| fig,ax = plt.subplots() |
| ax.pie([finished_resp,unfinish],labels = ["Finished","Not Finished"],autopct = '%2.2f%%') |
| c1 = "Educator, Response: "+str(finished_resp)+", Not Response: "+str(unfinish) |
| ax.set_title(c1) |
|
|
| return fig |
|
|
|
|
|
|
|
|
|
|
|
|
| |
| @session.download( |
| filename = f"result.csv" |
| ) |
| async def save_result(): |
| this_df = get_responses_check_df(curr_df,"INFO_1","INFO_5","INFO_6") |
| sz1,sz2 = this_df.shape |
| df_col = this_df.columns |
|
|
| yield df_col[0]+ ","+df_col[1]+","+df_col[2]+","+df_col[3]+ ","+df_col[4]+"\n" |
| for i in range(sz1): |
| yield str(this_df.iloc[i,0])+","+str(this_df.iloc[i,1])+","+str(this_df.iloc[i,2])+","+str(this_df.iloc[i,3])+","+str(this_df.iloc[i,4])+"\n" |
|
|
|
|
|
|
| app = App(app_ui, server) |
|
|