2828slope_selector_ui <- function (id ) {
2929 ns <- NS(id )
3030 assets <- system.file(" shiny/www" , package = " aNCA" )
31-
31+
3232 div(
3333 class = " slope-selector-module" ,
3434 manual_slopes_table_ui(ns(" manual_slopes" )),
@@ -45,36 +45,36 @@ slope_selector_ui <- function(id) {
4545 Please remember to apply your changes once you are done by clicking Run NCA again!
4646 " ),
4747 div(class = " gif-grid" ,
48- div(
49- class = " gif-container" ,
50- tags $ h1(" Check" ),
51- tags $ h6(" Hover the mouse over points to inspect individual samples." ),
52- img(src = " images/slope_plot_check.gif" , alt = " Check" )
53- ),
54- div(
55- class = " gif-container" ,
56- tags $ h1(" Zoom" ),
57- tags $ h6(" Click and drag to select and zoom in a specific area." ,
58- " Double click to zoom out."
59- ),
60- img(src = " images/slope_plot_zoom.gif" , alt = " Zoom" )
48+ div(
49+ class = " gif-container" ,
50+ tags $ h1(" Check" ),
51+ tags $ h6(" Hover the mouse over points to inspect individual samples." ),
52+ img(src = " images/slope_plot_check.gif" , alt = " Check" )
53+ ),
54+ div(
55+ class = " gif-container" ,
56+ tags $ h1(" Zoom" ),
57+ tags $ h6(" Click and drag to select and zoom in a specific area." ,
58+ " Double click to zoom out."
6159 ),
62- div(
63- class = " gif-container" ,
64- tags $ h1(" Select" ),
65- tags $ h6(" Click the first and then the last point" ,
66- " you want to include in the slope." ),
67- img(src = " images/slope_plot_select.gif" , alt = " Select" )
60+ img(src = " images/slope_plot_zoom.gif" , alt = " Zoom" )
61+ ),
62+ div(
63+ class = " gif-container" ,
64+ tags $ h1(" Select" ),
65+ tags $ h6(" Click the first and then the last point" ,
66+ " you want to include in the slope." ),
67+ img(src = " images/slope_plot_select.gif" , alt = " Select" )
68+ ),
69+ div(
70+ class = " gif-container" ,
71+ tags $ h1(" Exclude" ),
72+ tags $ h6(
73+ tags $ div(" Double click a point to exclude it." ),
74+ tags $ div(" Double click it again to include it back." )
6875 ),
69- div(
70- class = " gif-container" ,
71- tags $ h1(" Exclude" ),
72- tags $ h6(
73- tags $ div(" Double click a point to exclude it." ),
74- tags $ div(" Double click it again to include it back." )
75- ),
76- img(src = " images/slope_plot_exclude.gif" , alt = " Exclude" )
77- )
76+ img(src = " images/slope_plot_exclude.gif" , alt = " Exclude" )
77+ )
7878 )
7979 ),
8080 style = " unite" ,
@@ -130,32 +130,25 @@ slope_selector_server <- function( # nolint
130130) {
131131 moduleServer(id , function (input , output , session ) {
132132 log_trace(" {id}: Attaching server" )
133-
133+
134134 ns <- session $ ns
135-
135+
136136 pknca_data <- reactiveVal(NULL )
137137 plot_outputs <- reactiveVal(NULL )
138-
138+
139139 observeEvent(processed_pknca_data(), {
140140 req(processed_pknca_data())
141-
141+
142142 new_pknca_data <- processed_pknca_data()
143- # Keep main intervals where half.life or any dependent param is selected.
144- # get_halflife_plots() handles the rest (forcing half.life, clearing impute).
145- hl_dep_params <- intersect(
146- PKNCA :: get.parameter.deps(" half.life" ),
147- names(new_pknca_data $ intervals )
148- )
149143 new_pknca_data $ intervals <- new_pknca_data $ intervals %> %
150- filter(type_interval == " main" ) %> %
151- filter(half.life | if_any(all_of(hl_dep_params ))) %> %
144+ filter(type_interval == " main" , half.life ) %> %
152145 unique()
153146 changes <- detect_pknca_data_changes(
154147 old = pknca_data(),
155148 new = new_pknca_data ,
156149 reason_col = " REASON"
157150 )
158-
151+
159152 if (changes $ in_data ) {
160153 # New data or major changes: regenerate all plots
161154 plot_outputs(get_halflife_plots(
@@ -168,7 +161,7 @@ slope_selector_server <- function( # nolint
168161 # Add/remove plots based on intervals (selection from nca_setup.R)
169162 plot_outputs(handle_interval_change(new_pknca_data , pknca_data(), plot_outputs()))
170163 }
171-
164+
172165 # Update the searching widget choices based on the new data
173166 if (changes $ in_data | changes $ in_selected_intervals ) {
174167 updateSelectInput(
@@ -186,21 +179,21 @@ slope_selector_server <- function( # nolint
186179 group_conc_cols <- group_vars(pknca_data )
187180 group_conc_n_levels <- sapply(pknca_data $ conc $ data [group_conc_cols ], \(x ) length(unique(x )))
188181 group_cols_to_order <- group_conc_cols [group_conc_n_levels > 1 ]
189-
182+
190183 updateOrderInput(
191184 session = session ,
192185 inputId = " order_groups" ,
193186 items = group_cols_to_order
194187 )
195188 }
196-
189+
197190 # Save the plots for the zip download (nca_results.R)
198191 session $ userData $ results $ slope_selector <- plot_outputs()
199-
192+
200193 # Update the object for future comparisons
201194 pknca_data(new_pknca_data )
202195 })
203-
196+
204197 # Call the pagination/searcher module to:
205198 # - Providing indices of plots for the selected subject(s)
206199 # - Providing indices for which plots to display based on pagination
@@ -210,7 +203,7 @@ slope_selector_server <- function( # nolint
210203 plot_outputs = plot_outputs ,
211204 plots_per_page = reactive(input $ plots_per_page )
212205 )
213-
206+
214207 observe({
215208 req(plot_outputs())
216209 output $ slope_plots_ui <- renderUI({
@@ -224,13 +217,13 @@ slope_selector_server <- function( # nolint
224217 . [page_search $ page_start(): page_search $ page_end()]
225218 })
226219 })
227-
220+
228221 # Creates an initial version of the manual slope adjustments table with pknca_data
229222 # and handles the addition and deletion of rows through the UI
230223 slopes_table <- manual_slopes_table_server(" manual_slopes" , pknca_data , manual_slopes_override )
231224 manual_slopes <- slopes_table $ manual_slopes
232225 refresh_reactable <- slopes_table $ refresh_reactable
233-
226+
234227 # Define the click events for the point exclusion and selection in the slope plots
235228 last_click_data <- reactiveVal(NULL )
236229 observeEvent(event_data(" plotly_click" , priority = " event" ), {
@@ -245,24 +238,24 @@ slope_selector_server <- function( # nolint
245238 # Update reactive values: last click & manual slopes table
246239 last_click_data(click_result $ last_click_data )
247240 manual_slopes(click_result $ manual_slopes )
248-
241+
249242 # render rectable anew #
250243 shinyjs :: runjs(" memory = {};" ) # needed to properly reset reactable.extras widgets
251244 refresh_reactable(refresh_reactable() + 1 )
252245 })
253-
246+
254247 # ' Separate event handling updating displayed reactable upon every change (adding and removing
255248 # ' rows, plots selection, edits). This needs to be separate call, since simply re-rendering
256249 # ' the table would mean losing focus on text inputs when entering values.
257250 observeEvent(manual_slopes(), {
258251 req(manual_slopes())
259-
252+
260253 # Update reactable with rules
261254 reactable :: updateReactable(
262255 outputId = " manual_slopes" ,
263256 data = manual_slopes()
264257 )
265-
258+
266259 })
267260 # ' returns half life adjustments rules to update processed_pknca_data in nca_setup.R
268261 manual_slopes
0 commit comments