Skip to content

Commit

Permalink
clean and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Spinner committed Jan 20, 2025
1 parent 686095c commit bc66f5c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion R/format_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ format_pkncadose_data <- function(pkncaconc_data,
slice(1) %>%
ungroup() %>%
arrange(!!!syms(group_columns))

}

#' Create Dose Intervals Dataset
Expand Down
7 changes: 6 additions & 1 deletion R/general_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
#' @importFrom tern g_ipp
#' @export
general_lineplot <- function(
data, selected_analytes, selected_pcspec, selected_usubjids, colorby_var, time_scale, yaxis_scale, cycle = NULL
data, selected_analytes, selected_pcspec, selected_usubjids,
colorby_var, time_scale, yaxis_scale, cycle = NULL
) {

# Check if the data is empty
Expand All @@ -75,6 +76,10 @@ general_lineplot <- function(
DOSEA = factor(DOSEA),
id_var = interaction(!!!syms(colorby_var), sep = ", ")
)
# Check if the data is empty
if (nrow(preprocessed_data) == 0) {
return(ggplot() + ggtitle("No data available for selected parameters"))
}

# If there are predose records duplicate them in the previous line so they are considered
if ("ARRLT" %in% names(preprocessed_data) &&
Expand Down
5 changes: 3 additions & 2 deletions R/lambda_slope_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ lambda_slope_plot <- function(

# Obtain all information relevant regarding lambda calculation
lambda_res <- res_pknca_df %>%
filter(DOSNO == dosno, USUBJID == usubjid, ANALYTE == analyte, PCSPEC == pcspec, type_interval == "main") %>%
filter(DOSNO == dosno, USUBJID == usubjid, ANALYTE == analyte,
PCSPEC == pcspec, type_interval == "main") %>%
arrange(USUBJID, DOSNO, ANALYTE, PCSPEC, start, desc(end)) %>%
filter(!duplicated(paste0(USUBJID, DOSNO, PCSPEC, ANALYTE, PPTESTCD)))

Expand Down Expand Up @@ -236,7 +237,7 @@ lambda_slope_plot <- function(
pl <- pl %>%
# Make this trace the only one
add_trace(
data = plot_data %>% filter(DOSNO == dosno, USUBJID == usubjid,
data = plot_data %>% filter(DOSNO == dosno, USUBJID == usubjid,
ANALYTE == analyte, PCSPEC == pcspec),
x = ~TIME, y = ~log10(AVAL),
customdata = ~paste0(USUBJID, "_", DOSNO, "_", IX),
Expand Down
10 changes: 8 additions & 2 deletions inst/shiny/modules/slope_selector.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ slope_selector_ui <- function(id) {
.SLOPE_SELECTOR_COLUMNS <- c("TYPE", "PATIENT", "ANALYTE", "PCSPEC", "PROFILE", "IXrange", "REASON")

slope_selector_server <- function(
id, mydata, res_nca, profiles_per_patient, cycle_nca, analyte_nca, pcspec_nca, pk_nca_trigger, settings_upload
id, mydata, res_nca, profiles_per_patient,
cycle_nca, analyte_nca, pcspec_nca,
pk_nca_trigger, settings_upload
) {
moduleServer(id, function(input, output, session) {
log_trace("{id}: Attaching server")
Expand Down Expand Up @@ -402,7 +404,11 @@ slope_selector_server <- function(
shiny::debounce(750)

# Define the click events for the point exclusion and selection in the slope plots
last_click_data <- reactiveValues(patient = "", profile = "", analyte = "", pcspec = "", idx_pnt = "")
last_click_data <- reactiveValues(
patient = "", profile = "",
analyte = "", pcspec = "",
idx_pnt = ""
)
observeEvent(event_data("plotly_click", priority = "event"), {
# Store the information of the last click event #
click_data <- event_data("plotly_click")
Expand Down
21 changes: 12 additions & 9 deletions inst/shiny/modules/tab_visuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ tab_visuals_ui <- function(id) {
orderInput(
ns("summary_groupby"),
"..to hierarchically group by (order matters!):",
items = c( "ANALYTE", "PCSPEC", "DOSNO"),
items = c("ANALYTE", "PCSPEC", "DOSNO"),
width = shiny::validateCssUnit("100%"),
connect = ns("summary_groupby_source"),
placeholder = "Drag items here to group hierarchically..."
Expand Down Expand Up @@ -223,13 +223,14 @@ tab_visuals_server <- function(id, data, grouping_vars, res_nca) {
param_choices_pcspec <- data() %>%
pull(PCSPEC) %>%
unique()

updatePickerInput(
session,
"generalplot_pcspec",
choices = param_choices_pcspec,
selected = param_choices_pcspec[1]
)

# Update the usubjid picker input
param_choices_usubjid <- data() %>%
pull(USUBJID) %>%
Expand All @@ -244,7 +245,7 @@ tab_visuals_server <- function(id, data, grouping_vars, res_nca) {

# Update the colorby picker input
param_choices_colorby <- sort(
c("STUDYID", "PCSPEC", "ANALYTE", "DOSEA", "DOSNO", "USUBJID", grouping_vars())
c("STUDYID", "PCSPEC", "ANALYTE", "DOSEA", "DOSNO", "USUBJID", grouping_vars())
)

updatePickerInput(
Expand All @@ -262,7 +263,8 @@ tab_visuals_server <- function(id, data, grouping_vars, res_nca) {
updateSelectInput(
session,
"analyte_mean",
choices = sort(analyte_choices)
choices = sort(analyte_choices),
selected = analyte_choices[1]
)

# Update the studyidmean select input
Expand All @@ -275,20 +277,21 @@ tab_visuals_server <- function(id, data, grouping_vars, res_nca) {
"studyid_mean",
choices = sort(studyid_choices)
)

# Update pcspec mean choices
pcspec_choices <- data() %>%
pull(PCSPEC) %>%
unique()

updateSelectInput(
session,
"pcspec_mean",
choices = sort(pcspec_choices)
choices = sort(pcspec_choices),
selected = pcspec_choices[1]
)

# Update the selectidvar select input
idvar_choices <- c("ANALYTE","PCSPEC", "DOSEA", grouping_vars())
idvar_choices <- c("ANALYTE", "PCSPEC", "DOSEA", grouping_vars())

updateSelectInput(
session,
Expand Down
8 changes: 5 additions & 3 deletions inst/shiny/tabs/nca.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ observeEvent(data(), {
session,
inputId = "select_analyte",
label = "Choose the Analyte(s) :",
choices = unique(data()$ANALYTE)
choices = unique(data()$ANALYTE),
selected = unique(data()$ANALYTE)[1]
)
})

Expand All @@ -28,7 +29,8 @@ observeEvent(data(), {
session,
inputId = "select_pcspec",
label = "Choose the Specimen Type(s) :",
choices = unique(data()$PCSPEC)
choices = unique(data()$PCSPEC),
selected = unique(data()$PCSPEC)[1]
)
})

Expand Down Expand Up @@ -481,7 +483,7 @@ res_nca <- eventReactive(pk_nca_trigger(), {
myres$result <- myres$result %>%
inner_join(select(mydata()$dose$data, -exclude)) %>%
mutate(start = start - !!sym(mydata()$dose$columns$time),
end = end - !!sym(mydata()$dose$columns$time)) %>%
end = end - !!sym(mydata()$dose$columns$time)) %>%
select(names(myres$result))

# Return the result
Expand Down
16 changes: 9 additions & 7 deletions inst/shiny/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,22 @@ fluidPage(
# Selection of analyte
selectInput(
"select_analyte",
"Choose the Analyte :",
choices = NULL,
multiple = TRUE),
"Choose the Analyte(s) :",
choices = c("Please specify ANALYTE" = ""),
multiple = TRUE
),
# Selection of matrix
selectInput(
"select_pcspec",
"Choose the Matrix:",
choices = NULL,
multiple = TRUE),
"Choose the Specimen Type(s):",
choices = c("Please specify PCSPEC" = ""),
multiple = TRUE
),
selectInput(
"select_dosno",
"Choose the Dose Number:",
multiple = TRUE,
choices = c("Please specify ANALYTE in Data Selection" = "")
choices = c("Please specify ANALYTE first" = "")
),
br(),
actionButton("submit_analyte", "Submit"),
Expand Down

0 comments on commit bc66f5c

Please sign in to comment.