Skip to content

Commit b18e48c

Browse files
author
jwildfire
authored
Merge pull request #259 from SafetyGraphics/dev-v0.11.0
dev-v0.11.0
2 parents 7d021e5 + ca77319 commit b18e48c

File tree

118 files changed

+11039
-2317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+11039
-2317
lines changed

.Rbuildignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
^inst/eDISH_app/tests$
1+
^inst/safetyGraphics_app/tests$
22
^data-raw$
33
^.*\.Rproj$
44
^\.Rproj\.user$

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: safetyGraphics
22
Title: Create Interactive Graphics Related to Clinical Trial Safety
3-
Version: 0.10.1
3+
Version: 0.11.0
44
Authors@R: c(
55
person("Jeremy", "Wildfire", email = "[email protected]", role = c("cre","aut")),
66
person("Becca", "Krouse", role="aut"),
@@ -37,5 +37,6 @@ Imports:
3737
tibble,
3838
utils,
3939
haven,
40-
shinyWidgets
40+
shinyWidgets,
41+
tidyr
4142
VignetteBuilder: knitr

NAMESPACE

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(chartRenderer)
34
export(detectStandard)
4-
export(eDISH)
5-
export(eDISHOutput)
65
export(generateSettings)
76
export(getRequiredSettings)
87
export(getSettingsMetadata)
9-
export(renderEDISH)
10-
export(renderSafetyHistogram)
8+
export(output_chartRenderer)
9+
export(render_chartRenderer)
1110
export(safetyGraphicsApp)
12-
export(safetyHistogram)
13-
export(safetyHistogramOutput)
11+
export(trimSettings)
1412
export(validateSettings)
1513
import(DT)
1614
import(dplyr)
@@ -35,4 +33,5 @@ importFrom(stringr,str_detect)
3533
importFrom(stringr,str_split)
3634
importFrom(stringr,str_subset)
3735
importFrom(tibble,tibble)
36+
importFrom(tidyr,gather)
3837
importFrom(utils,globalVariables)

R/chartRenderer.R

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#' Create an interactive graphics widget
2+
#'
3+
#' This function creates an nice interactive widget. See this vingette for more details regarding how to customize charts.
4+
#'
5+
#' @param data A data frame containing the labs data. Data must be structured as one record per study participant per time point per lab measure.
6+
#' @param debug_js print settings in javascript before rendering chart. Default: \code{FALSE}.
7+
#' @param settings Optional list of settings arguments to be converted to JSON using \code{jsonlite::toJSON(settings, auto_unbox = TRUE, dataframe = "rows", null = "null")}. Default: \code{NULL}.
8+
#' @param chart name of the chart to render
9+
#'
10+
#' @examples
11+
#' \dontrun{
12+
#'
13+
#' ## Create Histogram figure using a premade settings list
14+
#' details_list <- list(
15+
#' list(value_col = "TRTP", label = "Treatment"),
16+
#' list(value_col = "SEX", label = "Sex"),
17+
#' list(value_col = "AGEGR1", label = "Age group")
18+
#' )
19+
#'
20+
#'
21+
#' filters_list <- list(
22+
#' list(value_col = "TRTA", label = "Treatment"),
23+
#' list(value_col = "SEX", label = "Sex"),
24+
#' list(value_col = "RACE", label = "RACE"),
25+
#' list(value_col = "AGEGR1", label = "Age group")
26+
#' )
27+
#'
28+
#' settingsl <- list(id_col = "USUBJID",
29+
#' value_col = "AVAL",
30+
#' measure_col = "PARAM",
31+
#' unit_col = "PARAMCD",
32+
#' normal_col_low = "A1LO",
33+
#' normal_col_high = "A1HI",
34+
#' details = details_list,
35+
#' filters = filters_list)
36+
#'
37+
#' chartRenderer(data=adlbc, settings = settingsl, chart=safetyhistogram)
38+
#'
39+
#' }
40+
#'
41+
#' @import htmlwidgets
42+
#'
43+
#' @export
44+
chartRenderer <- function(data, debug_js = FALSE, settings = NULL, chart=NULL) {
45+
# Chart specific customizastions (to be removed after js updates)
46+
if(chart %in% c("paneledoutlierexplorer","safetyoutlierexplorer")){
47+
settings$time_cols <- list(list(),list());
48+
settings$time_cols[[1]]<-list(
49+
type= "ordinal",
50+
value_col= settings[["visit_col"]],
51+
label= "Visit",
52+
order_col= settings[["visitn_col"]],
53+
order= NULL,
54+
rotate_tick_labels= TRUE,
55+
vertical_space= 100
56+
)
57+
settings$time_cols[[2]]<-list(
58+
type= "linear",
59+
value_col= settings[["studyday_col"]],
60+
label= "Study Day",
61+
order_col= settings[["studyday_col"]],
62+
order= NULL,
63+
rotate_tick_labels= FALSE,
64+
vertical_space= 0
65+
)
66+
}
67+
68+
if(chart=="paneledoutlierexplorer"){
69+
settings$lln_col <- settings[["normal_col_low"]]
70+
settings$uln_col <- settings[["normal_col_high"]]
71+
}
72+
73+
if(chart=="safetyshiftplot"){
74+
settings$time_col<-settings[["visit_col"]]
75+
}
76+
77+
if(chart=="safetyresultsovertime"){
78+
settings$time_settings=list(
79+
value_col= settings[["visit_col"]],
80+
label= "Visit",
81+
order_col= settings[["visitn_col"]],
82+
order= NULL,
83+
rotate_tick_labels= TRUE,
84+
vertical_space= 100
85+
)
86+
87+
settings$groups = settings$group_cols
88+
}
89+
90+
#Set Chart Width
91+
chartMaxWidth<- safetyGraphics::chartsMetadata %>% filter(.data$chart==!!chart) %>% pull(.data$maxWidth)
92+
settings$max_width <- chartMaxWidth
93+
94+
#Renderer
95+
chartFunction<- safetyGraphics::chartsMetadata %>% filter(.data$chart==!!chart) %>% pull(.data$main)
96+
rSettings = list(
97+
data = data,
98+
debug_js=debug_js,
99+
chartFunction = chartFunction,
100+
settings = jsonlite::toJSON(
101+
settings,
102+
auto_unbox = TRUE,
103+
null = "null"
104+
)
105+
)
106+
107+
# create widget
108+
htmlwidgets::createWidget(
109+
name = 'chartRenderer',
110+
rSettings,
111+
# width = width,
112+
# height = height,
113+
package = 'safetyGraphics',
114+
sizingPolicy = htmlwidgets::sizingPolicy(viewer.suppress=TRUE, browser.external = TRUE)
115+
)
116+
}
117+
118+
#' Shiny bindings for chartRenderer
119+
#'
120+
#' Output and render functions for using safetyhistogram within Shiny
121+
#' applications and interactive Rmd documents.
122+
#'
123+
#' @param outputId output variable to read from
124+
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
125+
#' \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
126+
#' string and have \code{'px'} appended.
127+
#' @param expr An expression that generates a chart
128+
#' @param env The environment in which to evaluate \code{expr}.
129+
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
130+
#' is useful if you want to save an expression in a variable.
131+
#'
132+
#' @name chartRenderer-shiny
133+
#'
134+
#' @export
135+
output_chartRenderer <- function(outputId, width = '100%', height = '400px'){
136+
htmlwidgets::shinyWidgetOutput(outputId, 'chartRenderer', width, height, package = 'safetyGraphics')
137+
}
138+
139+
#' @rdname chartRenderer-shiny
140+
#' @export
141+
render_chartRenderer <- function(expr, env = parent.frame(), quoted = FALSE) {
142+
if (!quoted) { expr <- substitute(expr) } # force quoted
143+
htmlwidgets::shinyRenderWidget(expr, output_chartRenderer, env, quoted = TRUE)
144+
}

R/chartsMetadata.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#' Charts Metadata
2+
#'
3+
#' Metadata about the charts available in the shiny app
4+
#'
5+
#' @format A data frame with 29 rows and 7 columns
6+
#' \describe{
7+
#' \item{chart}{Name of the chart - one word, all lower case}
8+
#' \item{label}{Nicely formatted name of the chart}
9+
#' \item{description}{Description of the chart}
10+
#' \item{repo_url}{Homepage for chart's code repository (if any)}
11+
#' \item{settings_url}{Homepage for chart's settings documentation}
12+
#' \item{main}{Name of the main function used to initialize the app. The function must accept "location" and "settings" parameters (in that order) and have an .init() method, expecting a json data array.}
13+
#' \item{type}{type of chart (e.g. 'htmlwidget')}
14+
#' \item{maxWidth}{max width for the widget in pixels}
15+
#' }
16+
#'
17+
#' @source Created for this package
18+
"chartsMetadata"

0 commit comments

Comments
 (0)