Skip to content

Commit

Permalink
update ui for three shiny apps
Browse files Browse the repository at this point in the history
  • Loading branch information
fcgrolleau committed Aug 21, 2024
1 parent ead4bf2 commit 5d15747
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 66 deletions.
2 changes: 1 addition & 1 deletion scripts/DevWorkshop/ROC-power/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Webpage with Sidebar Links</title>
<title>powerROC -- An Interactive Web Tool for Sample Size Calculation </title>
<style>
body {
display: flex;
Expand Down
20 changes: 16 additions & 4 deletions scripts/DevWorkshop/ROC-power/shinyapp/basic-app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ui.h4("Specifying parameters of two joint distributions"),
ui.br(),
ui.h4("- Inputs"),
"In the absence of a pilot test set, you can manually specify a distribution for the evaluation population (illustrated in real-time in the contour plots below.)",
"In the absence of a pilot test set, please manually specify a distribution for the evaluation population, which will be illustrated in real-time in the contour plots below.",
ui.p("Once this distribution is specified, use ", ui.em("Run the simulations.")),
ui.row(
ui.column(
Expand Down Expand Up @@ -108,9 +108,21 @@ def ui_text_meth():
@render.ui
@reactive.event(input.change_var1, input.change_cor1, input.change_var2, input.change_cor2)
def ui_spacing():
if input.change_var1() and input.change_cor2():
return ui.h4("- Results")
if input.change_var2() and not input.change_cor2() and not input.change_var1():
if input.change_cor1():
return ui.div({"style": "margin-bottom: 140px;"}), ui.h4("- Results")
else:
return ui.div({"style": "margin-bottom: 275px;"}), ui.h4("- Results")
elif input.change_cor2() and not input.change_var2() and not input.change_var1() and not input.change_cor1():
return ui.div({"style": "margin-bottom: 140px;"}), ui.h4("- Results")
elif input.change_var2() and input.change_cor2() and not (input.change_var1() and input.change_cor1()):
if input.change_cor1():
return ui.div({"style": "margin-bottom: 270px;"}), ui.h4("- Results")
elif input.change_var1():
return ui.div({"style": "margin-bottom: 135px;"}), ui.h4("- Results")
else:
return ui.div({"style": "margin-bottom: 400px;"}), ui.h4("- Results")
else:
return ui.h4("- Results") # ui.div({"style": "margin-bottom: 400px;"})
return ui.h4("- Results")

app = App(app_ui, server)
20 changes: 12 additions & 8 deletions scripts/DevWorkshop/ROC-power/shinyapp/collins/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# rsconnect deploy shiny shinyapp/collins --name francois-grolleau --title prec_auroc1
# rsconnect deploy shiny shinyapp/pilot --name francois-grolleau --title ss_auroc_pilot
# rsconnect deploy shiny shinyapp/basic-app --name francois-grolleau --title ss_auroc

from shiny import App, render, ui
from scipy.stats import norm
from stat_custom import collins_c
Expand All @@ -6,21 +10,21 @@
ui.panel_title("Sample Size Needed to Precisely Estimate a Model's Area Under the ROC Curve"),
ui.br(),
ui.h4("- Inputs"),
"Anticipated AUROC in the evaluation population",
ui.input_slider("auroc", label=ui.em('How well do we expect the model to perform on the test set?'), value=.77, step=.01, min=.5, max=1-1e-2, width="600px"),
"Prevalence in the evaluation population",
ui.input_slider("prev", label=ui.em('What is the anticipated proportion of events in the test set?'), value=.43, step=.01, min=1e-2, max=1-1e-2, width="600px"),
"Target width for the estimated AUROC 95% confidence interval",
ui.input_numeric("targ_ciw", label=ui.em('What level of precision do we aim to achieve for model evaluation?'), value=.1, step=.0001, min=1e-2, max=1-1e-2, width="600px"),
ui.input_slider("auroc", label=ui.p(ui.strong(ui.div({"style": ""},"Anticipated AUROC in the evaluation population")), ui.em("How well do we expect the model to perform on the test set?")), value=.77, step=.01, min=.5, max=1-1e-2, width="600px"),
ui.input_slider("prev", label=ui.p(ui.strong(ui.div({"style": ""},"Prevalence in the evaluation population")), ui.em("What is the anticipated proportion of events in the test set?")), value=.43, step=.01, min=1e-2, max=1-1e-2, width="600px"),
ui.input_numeric("targ_ciw", label=ui.p(ui.strong(ui.div({"style": ""},"Target width for the estimated AUROC 95% confidence interval")), ui.em("What level of precision do we aim to achieve for model evaluation?")), value=.1, step=.0001, min=1e-2, max=1-1e-2, width="600px"),
ui.br(),
ui.h4("- Result"),
ui.div(
{"style": "font-weight: bold; text-indent: 40px;"},
{"style": "font-weight: bold; text-indent: 40px; font-size: 18px;"},
ui.output_text("txt2"),
),
ui.output_text("txt1"),
ui.br(),
ui.h4("- References"),
ui.h4("- Methods"),
"Our code uses an iterative process over the equation given in the references below to identify the sample size needed to achieve the desired precision for the AUROC estimate.",
ui.div({"style": "margin-bottom: 20px;"}),
"References:",
ui.br(),
"- Riley et al. Evaluation of clinical prediction models (part 3): calculating the sample size required for an external validation study. BMJ (2024) [See Figure 3, Criterion 3, ",
ui.a("link", href="https://www.bmj.com/content/384/bmj-2023-074821", target="_blank"), "].",
Expand Down
8 changes: 4 additions & 4 deletions scripts/DevWorkshop/ROC-power/shinyapp/pilot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
ui.output_ui("ui_prev"),
ui.br(),
ui.row(
ui.input_slider("alpha_t", label=ui.p("Alpha threshold", ui.br(), ui.em("Significance level, typically set to 0.05")), value=.05, step=.01, min=1e-2, max=1-1e-2, width='300px'),
ui.input_numeric("ss", label=ui.p("Sample size for power calculation", ui.br(), ui.em("Calculations are also performed at 0.5 and 1.5 that sample size")), value=1060, min=100, max=100000, width='475px'),
ui.input_select("n_sim", label=ui.p(ui.strong("Run the simulations"), ui.br(), ui.em("Choose no. of iterations")), choices={100: "100 iteration (fastest, least accurate)", 500: "500 iterations (intermediate)", 2000: "2000 iterations (slowest, most accurate)"}),
ui.input_slider("alpha_t", label=ui.p(ui.strong(ui.div({"style": ""},"Alpha threshold")), ui.em("Significance level, typically set to 0.05")), value=.05, step=.01, min=1e-2, max=1-1e-2, width='300px'),
ui.input_numeric("ss", label=ui.p(ui.strong(ui.div({"style": ""}, "Sample size for power calculation")), ui.em("Calculations are also performed at 0.5 and 1.5 that sample size")), value=1060, min=100, max=100000, width='475px'),
ui.input_select("n_sim", label=ui.p(ui.strong(ui.div({"style": "font-weight: bold; color: red;"}, "Run the simulations")), ui.em("Choose no. of iterations")), choices={100: "100 iteration (fastest, least accurate)", 500: "500 iterations (intermediate)", 2000: "2000 iterations (slowest, most accurate)"}),
),
ui.br(),
ui.h4("- Results"),
Expand All @@ -32,7 +32,7 @@ def server(input: Inputs, output: Outputs, session: Session):
def text():
df = parsed_file()
if getattr(df, "orig", False):
return "Your CSV file should follow the column order as illustrated in the example: Event, Prediction from Model A, Prediction from Model B. Note that the specific column names are not required, only the order matters. For accurate sample size calculations, we recommend including a minimum of five events and five non-events in your dataset. Before you upload your CSV file, we will use the example dataset below to demonstrate sample size calculation. Upon upload, the first ten rows of your pilot test will be shown for sanity checks."
return 'Your CSV file should follow this column order: Event, Prediction from Model A, Prediction from Model B. The specific column names are not important. Note that reversing "Prediction from Model A" and "Prediction from Model B" makes no difference. For accurate sample size calculations, include at least five events and five non-events. Before you upload your CSV file, we will use the example dataset below to demonstrate sample size calculation. Upon upload, the first ten rows of your pilot test will be shown for sanity checks.'
return "The first 10 rows of your uploaded test set are displayed below."

@reactive.calc
Expand Down
Loading

0 comments on commit 5d15747

Please sign in to comment.