Skip to content

Commit

Permalink
Merge pull request #259 from SafetyGraphics/dev-v0.11.0
Browse files Browse the repository at this point in the history
dev-v0.11.0
  • Loading branch information
jwildfire authored May 17, 2019
2 parents 7d021e5 + ca77319 commit b18e48c
Show file tree
Hide file tree
Showing 118 changed files with 11,039 additions and 2,317 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
^inst/eDISH_app/tests$
^inst/safetyGraphics_app/tests$
^data-raw$
^.*\.Rproj$
^\.Rproj\.user$
Expand Down
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: safetyGraphics
Title: Create Interactive Graphics Related to Clinical Trial Safety
Version: 0.10.1
Version: 0.11.0
Authors@R: c(
person("Jeremy", "Wildfire", email = "jeremy_wildfire@rhoworld.com", role = c("cre","aut")),
person("Becca", "Krouse", role="aut"),
Expand Down Expand Up @@ -37,5 +37,6 @@ Imports:
tibble,
utils,
haven,
shinyWidgets
shinyWidgets,
tidyr
VignetteBuilder: knitr
11 changes: 5 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Generated by roxygen2: do not edit by hand

export(chartRenderer)
export(detectStandard)
export(eDISH)
export(eDISHOutput)
export(generateSettings)
export(getRequiredSettings)
export(getSettingsMetadata)
export(renderEDISH)
export(renderSafetyHistogram)
export(output_chartRenderer)
export(render_chartRenderer)
export(safetyGraphicsApp)
export(safetyHistogram)
export(safetyHistogramOutput)
export(trimSettings)
export(validateSettings)
import(DT)
import(dplyr)
Expand All @@ -35,4 +33,5 @@ importFrom(stringr,str_detect)
importFrom(stringr,str_split)
importFrom(stringr,str_subset)
importFrom(tibble,tibble)
importFrom(tidyr,gather)
importFrom(utils,globalVariables)
144 changes: 144 additions & 0 deletions R/chartRenderer.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#' Create an interactive graphics widget
#'
#' This function creates an nice interactive widget. See this vingette for more details regarding how to customize charts.
#'
#' @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.
#' @param debug_js print settings in javascript before rendering chart. Default: \code{FALSE}.
#' @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}.
#' @param chart name of the chart to render
#'
#' @examples
#' \dontrun{
#'
#' ## Create Histogram figure using a premade settings list
#' details_list <- list(
#' list(value_col = "TRTP", label = "Treatment"),
#' list(value_col = "SEX", label = "Sex"),
#' list(value_col = "AGEGR1", label = "Age group")
#' )
#'
#'
#' filters_list <- list(
#' list(value_col = "TRTA", label = "Treatment"),
#' list(value_col = "SEX", label = "Sex"),
#' list(value_col = "RACE", label = "RACE"),
#' list(value_col = "AGEGR1", label = "Age group")
#' )
#'
#' settingsl <- list(id_col = "USUBJID",
#' value_col = "AVAL",
#' measure_col = "PARAM",
#' unit_col = "PARAMCD",
#' normal_col_low = "A1LO",
#' normal_col_high = "A1HI",
#' details = details_list,
#' filters = filters_list)
#'
#' chartRenderer(data=adlbc, settings = settingsl, chart=safetyhistogram)
#'
#' }
#'
#' @import htmlwidgets
#'
#' @export
chartRenderer <- function(data, debug_js = FALSE, settings = NULL, chart=NULL) {
# Chart specific customizastions (to be removed after js updates)
if(chart %in% c("paneledoutlierexplorer","safetyoutlierexplorer")){
settings$time_cols <- list(list(),list());
settings$time_cols[[1]]<-list(
type= "ordinal",
value_col= settings[["visit_col"]],
label= "Visit",
order_col= settings[["visitn_col"]],
order= NULL,
rotate_tick_labels= TRUE,
vertical_space= 100
)
settings$time_cols[[2]]<-list(
type= "linear",
value_col= settings[["studyday_col"]],
label= "Study Day",
order_col= settings[["studyday_col"]],
order= NULL,
rotate_tick_labels= FALSE,
vertical_space= 0
)
}

if(chart=="paneledoutlierexplorer"){
settings$lln_col <- settings[["normal_col_low"]]
settings$uln_col <- settings[["normal_col_high"]]
}

if(chart=="safetyshiftplot"){
settings$time_col<-settings[["visit_col"]]
}

if(chart=="safetyresultsovertime"){
settings$time_settings=list(
value_col= settings[["visit_col"]],
label= "Visit",
order_col= settings[["visitn_col"]],
order= NULL,
rotate_tick_labels= TRUE,
vertical_space= 100
)

settings$groups = settings$group_cols
}

#Set Chart Width
chartMaxWidth<- safetyGraphics::chartsMetadata %>% filter(.data$chart==!!chart) %>% pull(.data$maxWidth)
settings$max_width <- chartMaxWidth

#Renderer
chartFunction<- safetyGraphics::chartsMetadata %>% filter(.data$chart==!!chart) %>% pull(.data$main)
rSettings = list(
data = data,
debug_js=debug_js,
chartFunction = chartFunction,
settings = jsonlite::toJSON(
settings,
auto_unbox = TRUE,
null = "null"
)
)

# create widget
htmlwidgets::createWidget(
name = 'chartRenderer',
rSettings,
# width = width,
# height = height,
package = 'safetyGraphics',
sizingPolicy = htmlwidgets::sizingPolicy(viewer.suppress=TRUE, browser.external = TRUE)
)
}

#' Shiny bindings for chartRenderer
#'
#' Output and render functions for using safetyhistogram within Shiny
#' applications and interactive Rmd documents.
#'
#' @param outputId output variable to read from
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
#' \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
#' string and have \code{'px'} appended.
#' @param expr An expression that generates a chart
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#'
#' @name chartRenderer-shiny
#'
#' @export
output_chartRenderer <- function(outputId, width = '100%', height = '400px'){
htmlwidgets::shinyWidgetOutput(outputId, 'chartRenderer', width, height, package = 'safetyGraphics')
}

#' @rdname chartRenderer-shiny
#' @export
render_chartRenderer <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
htmlwidgets::shinyRenderWidget(expr, output_chartRenderer, env, quoted = TRUE)
}
18 changes: 18 additions & 0 deletions R/chartsMetadata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#' Charts Metadata
#'
#' Metadata about the charts available in the shiny app
#'
#' @format A data frame with 29 rows and 7 columns
#' \describe{
#' \item{chart}{Name of the chart - one word, all lower case}
#' \item{label}{Nicely formatted name of the chart}
#' \item{description}{Description of the chart}
#' \item{repo_url}{Homepage for chart's code repository (if any)}
#' \item{settings_url}{Homepage for chart's settings documentation}
#' \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.}
#' \item{type}{type of chart (e.g. 'htmlwidget')}
#' \item{maxWidth}{max width for the widget in pixels}
#' }
#'
#' @source Created for this package
"chartsMetadata"
Loading

0 comments on commit b18e48c

Please sign in to comment.