| | import asyncio
|
| | from datetime import datetime, date, time
|
| |
|
| | from faicons import icon_svg
|
| |
|
| | from modules.get_rules_in_window import (
|
| | DF,
|
| | LAST_UPDATED,
|
| | START_DATE,
|
| | GET_SIGNIFICANT,
|
| | METADATA,
|
| | groupby_agency,
|
| | groupby_ym,
|
| | plot_agency,
|
| | plot_month,
|
| | )
|
| |
|
| | from shiny import reactive
|
| | from shiny.express import input, render, ui
|
| |
|
| | FOOTER = f"""
|
| | -----
|
| |
|
| | Developed by the [GW Regulatory Studies Center](https://go.gwu.edu/regstudies). See our page on the [Congressional Review Act](https://regulatorystudies.columbian.gwu.edu/congressional-review-act) for more information.
|
| | """
|
| |
|
| | ui.page_opts(
|
| | title="Rules in the Congressional Review Act (CRA) Window",
|
| | )
|
| |
|
| | with ui.sidebar(title="Settings"):
|
| | ui.input_date("start_date", "Start of window", value=START_DATE, min=START_DATE, max=date.today())
|
| |
|
| | ui.input_switch("switch", "Show significant rules in plots", False)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | with ui.layout_column_wrap():
|
| | with ui.value_box(showcase=icon_svg("book")):
|
| | "All final rules"
|
| |
|
| | @render.text
|
| | def count_rules():
|
| | return f"{filtered_df()['document_number'].count()}"
|
| |
|
| | with ui.value_box(showcase=icon_svg("book")):
|
| | "Other Significant rules"
|
| |
|
| | @render.text
|
| | def count_other_significant():
|
| | output = "Not available"
|
| | if GET_SIGNIFICANT:
|
| | output = f"{filtered_df()['other_significant'].sum()}"
|
| | return output
|
| |
|
| | with ui.value_box(showcase=icon_svg("book")):
|
| | "Section 3(f)(1) Significant rules"
|
| |
|
| | @render.text
|
| | def count_3f1_significant():
|
| | output = "Not available"
|
| | if GET_SIGNIFICANT:
|
| | output = f"{filtered_df()['3f1_significant'].sum()}"
|
| | return output
|
| |
|
| | with ui.navset_card_underline(title=""):
|
| |
|
| | with ui.nav_panel("Rules in detail"):
|
| | @render.data_frame
|
| | def table_rule_detail():
|
| | df = filtered_df()
|
| |
|
| |
|
| | df.loc[:, "date"] = df.apply(lambda x: f"{x['publication_date'].date()}", axis=1)
|
| | char = " "
|
| | df.loc[:, "title"] = df["title"].apply(lambda x: f"{char.join(x.split(char)[:9])}...")
|
| | df.loc[:, "agencies"] = df["parent_slug"].apply(lambda x: "; ".join(x))
|
| | cols = [
|
| | "date",
|
| | "title",
|
| | "agencies",
|
| | "3f1_significant",
|
| | "other_significant",
|
| | ]
|
| | return render.DataTable(df.loc[:, [c for c in cols if c in df.columns]])
|
| |
|
| | with ui.nav_panel("By month"):
|
| |
|
| | with ui.layout_columns():
|
| |
|
| | @render.plot
|
| | def plot_by_month():
|
| | grouped = grouped_df_month()
|
| | return plot_month(
|
| | grouped
|
| | )
|
| |
|
| | @render.data_frame
|
| | def table_by_month():
|
| | grouped = grouped_df_month()
|
| | cols = [
|
| | "publication_year",
|
| | "publication_month",
|
| | "rules",
|
| | "3f1_significant",
|
| | "other_significant",
|
| | ]
|
| | return render.DataTable(grouped.loc[:, [c for c in cols if c in grouped.columns]])
|
| |
|
| | with ui.nav_panel("By agency"):
|
| |
|
| | with ui.layout_columns():
|
| |
|
| | @render.plot
|
| | def plot_by_agency():
|
| | grouped = grouped_df_agency()
|
| | return plot_agency(
|
| | grouped.head(10),
|
| | )
|
| |
|
| | @render.data_frame
|
| | def table_by_agency():
|
| | grouped = grouped_df_agency()
|
| | cols = [
|
| | "agency",
|
| | "acronym",
|
| | "rules",
|
| | "3f1_significant",
|
| | "other_significant",
|
| | ]
|
| | return render.DataTable(grouped.loc[:, [c for c in cols if c in grouped.columns]])
|
| |
|
| | with ui.accordion(open=False):
|
| |
|
| | with ui.accordion_panel("Download Data"):
|
| |
|
| | @render.download(
|
| | label="Download data as CSV",
|
| | filename=f"rules_in_cra_window_accessed_{date.today()}.csv",
|
| | )
|
| | async def download():
|
| | await asyncio.sleep(0.25)
|
| | yield filtered_df().to_csv(index=False)
|
| |
|
| | with ui.accordion(open=False):
|
| |
|
| | with ui.accordion_panel("Notes"):
|
| |
|
| | ui.markdown(
|
| | f"""
|
| | Rule data retrieved from the [Federal Register API](https://www.federalregister.gov/developers/documentation/api/v1).
|
| |
|
| | Executive Order 12866 significance data last updated **{LAST_UPDATED}**.
|
| | """
|
| | )
|
| |
|
| | ui.markdown(
|
| | FOOTER
|
| | )
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | @reactive.calc
|
| | def filtered_df():
|
| | filt_df = DF
|
| |
|
| | try:
|
| | filt_df = filt_df.loc[filt_df["publication_date"] >= input.start_date()]
|
| | except TypeError:
|
| | filt_df = filt_df.loc[filt_df["publication_date"] >= datetime.combine(input.start_date(), time(0, 0))]
|
| | return filt_df
|
| |
|
| | @reactive.calc
|
| | def grouped_df_month():
|
| | filt_df = filtered_df()
|
| | grouped = groupby_ym(filt_df, significant=GET_SIGNIFICANT)
|
| | return grouped
|
| |
|
| | @reactive.calc
|
| | def grouped_df_agency():
|
| | filt_df = filtered_df()
|
| | grouped = groupby_agency(filt_df, metadata=METADATA, significant=GET_SIGNIFICANT)
|
| | return grouped
|
| |
|