Created
July 16, 2019 08:53
-
-
Save zappingseb/0216a29558d214a44468e592ca4e03b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create the dataset by merging the two tables per patient | |
data_set_reactive <- metaReactive({ | |
event_data_filtered <- event_data %>% dplyr::filter(PARAMCD == !!input$filter_param) | |
ads_selected <- pat_data %>% dplyr::select(dplyr::one_of(c(!!input$select_regressor, c("SUBJID", "STUDYID")))) | |
merge(ads_selected, event_data_filtered, by = c("SUBJID", "STUDYID")) | |
}) | |
# Create a pure reactive to create the formula shown in the linear model | |
formula_reactive <- reactive({ | |
validate(need(is.character(input$select_regressor), "Cannot work without selected column")) | |
stats::as.formula(paste("AVAL", paste(input$select_regressor, collapse = " + "), sep = " ~ ")) | |
}) | |
# Create a linear model | |
model_reactive <- metaReactive2({ | |
validate(need(is.data.frame(data_set_reactive()), "Data Set could not be created")) | |
validate(need(is.language(formula_reactive()), "Formula could not be created from column selections")) | |
metaExpr({ | |
model_data <- !!data_set_reactive() | |
lm(formula = !!formula_reactive(), data = model_data) | |
}) | |
}) | |
# Plot Regression vs fitted | |
output$plot1 <- metaRender(renderPlot, { | |
plot(!!model_reactive(), which = 1) | |
}) | |
# show model summary | |
output$text1 <- metaRender(renderPrint, { | |
!!model_reactive() %>% summary() | |
}) | |
# Show Code to produce the Outputs | |
observeEvent(input$show_r_code, { | |
showModal(modalDialog( | |
title = "R Code", | |
tags$pre( | |
id = "r_code", | |
expandChain( | |
library_code, | |
data_code, | |
output$plot1(), | |
output$text1() | |
) %>% formatCode() %>% paste(collapse = "\n") | |
), | |
footer = tagList( | |
actionButton("copyRCode", "Copy to Clipboard", `data-clipboard-target` = "#r_code"), | |
modalButton("Dismiss") | |
), | |
size = "l", | |
easyClose = TRUE | |
)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment