@@ -158,19 +158,19 @@ patient_plot_server <- function(id, subject_var,
158158 # Compute plots ----
159159
160160 timeline_limits <- local({ # start...end, but takes icf and part_end dates into account if available
161- min_total <- subject_level_dataset [[ timeline_info [[ " trt_start_date" ]] ]]
161+ min_total <- sl_info [[ " trt_start_date" ]]
162162 if (" icf_date" %in% names(timeline_info )) {
163- icf_date <- subject_level_dataset [[ timeline_info [[ " icf_date" ]] ]]
163+ icf_date <- sl_info [[ " icf_date" ]]
164164 if (is.finite(icf_date )) min_total <- icf_date
165165 }
166166
167167 max_total <- as.Date(- Inf )
168- trt_end_date <- subject_level_dataset [[ timeline_info [[ " trt_end_date" ]] ]]
168+ trt_end_date <- sl_info [[ " trt_end_date" ]]
169169 if (is.finite(trt_end_date )) {
170170 max_total <- trt_end_date
171171 }
172172 if (" part_end_date" %in% names(timeline_info )) {
173- part_end_date <- subject_level_dataset [[ timeline_info [[ " part_end_date" ]] ]]
173+ part_end_date <- sl_info [[ " part_end_date" ]]
174174 if (is.finite(part_end_date )) max_total <- part_end_date
175175 }
176176 if (! is.finite(max_total )) max_total <- Sys.Date()
@@ -180,10 +180,11 @@ patient_plot_server <- function(id, subject_var,
180180
181181 x_limits <- local({ # we need to compute combined limits first because ggplot+plotly need them before layout calculation
182182 # the +/-1 avoids clipping the left and right arrows on the plot
183- diff <- timeline_limits [[2 ]] - timeline_limits [[1 ]]
184- offset_left <- min(- 1L , round(- diff / 10 ))
185- offset_right <- max(1L , round(diff / 10 ))
186- c(timeline_limits [[1 ]] + offset_left , timeline_limits [[2 ]] + offset_right )
183+ timeline_limit_lower <- timeline_limits [[1 ]]
184+ timeline_limit_upper <- timeline_limits [[2 ]]
185+ diff <- timeline_limit_upper - timeline_limit_lower
186+ offset <- max(1L , round(diff / 10 ))
187+ c(timeline_limit_lower - offset , timeline_limit_upper + offset )
187188 })
188189
189190 plot_list <- local({
@@ -423,6 +424,10 @@ patient_plot_server <- function(id, subject_var,
423424 heights = heights / sum(heights )
424425 )
425426
427+ # Force legend visibility after subplot construction, since by default
428+ # if any plot does not have a legend then combined plot loses legend.
429+ plots $ x $ layout $ showlegend <- TRUE
430+
426431 x_limits_z <- x_limits - sl_info [[" trt_start_date" ]]
427432 plots <- silence_warning(
428433 plotly :: layout(plots , height = sum(heights ), xaxis = list (range = x_limits_z )),
0 commit comments