From 792a7688aee64f8e307e3f5e77cb19fbee37973a Mon Sep 17 00:00:00 2001 From: Chuck McCallum Date: Fri, 18 Oct 2024 15:12:49 -0400 Subject: [PATCH] Logarithmic epsilon slider (#65) * log epsilon slider * Use CSS to hide numbers we do not need --- dp_creator_ii/app/analysis_panel.py | 16 ++++++++++++---- dp_creator_ii/app/css/styles.css | 5 +++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/dp_creator_ii/app/analysis_panel.py b/dp_creator_ii/app/analysis_panel.py index e03336d..8c11633 100644 --- a/dp_creator_ii/app/analysis_panel.py +++ b/dp_creator_ii/app/analysis_panel.py @@ -1,3 +1,5 @@ +from math import pow + from shiny import ui, reactive, render from dp_creator_ii.mock_data import mock_data, ColumnDef @@ -22,10 +24,8 @@ def analysis_ui(): "Values above 1 will add less noise to the data, " "but have greater risk of revealing individual data." ), - ui.markdown( - "[TODO: Logarithmic slider]" - "(https://github.com/opendp/dp-creator-ii/issues/25)" - ), + ui.input_slider("log_epsilon_slider", None, -1, 1, 0, step=0.1), + ui.output_text("epsilon"), ui.markdown( "## Preview\n" "These plots assume a normal distribution for the columns you've selected, " @@ -39,6 +39,14 @@ def analysis_ui(): def analysis_server(input, output, session): + @reactive.calc + def epsilon_calc(): + return pow(10, input.log_epsilon_slider()) + + @render.text + def epsilon(): + return f"Epsilon: {epsilon_calc():0.3}" + @render.plot() def plot_preview(): min_x = 0 diff --git a/dp_creator_ii/app/css/styles.css b/dp_creator_ii/app/css/styles.css index 6b38283..6834e2c 100644 --- a/dp_creator_ii/app/css/styles.css +++ b/dp_creator_ii/app/css/styles.css @@ -5,3 +5,8 @@ body { #top_level_nav { margin-bottom: 1em; } + +/* Rather than engineer a new widget, hide the numbers we don't want. */ +.irs-min, .irs-max, .irs-single { + display: none; +}