Skip to content

Instantly share code, notes, and snippets.

@zappingseb
Last active July 16, 2019 21:27
Show Gist options
  • Save zappingseb/4ade142cf762e1f47d42661790b2e13c to your computer and use it in GitHub Desktop.
Save zappingseb/4ade142cf762e1f47d42661790b2e13c to your computer and use it in GitHub Desktop.
Server function for non-reproducible app
# Create a linear model
model_reactive <- reactive({
validate(need(is.character(input$select_regressor), "Cannot work without selected column"))
regressors <- Reduce(function(x, y) call("+", x, y), rlang::syms(input$select_regressor))
formula_value <- rlang::new_formula(rlang::sym("AVAL"), regressors)
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"))))
anl <- merge(ads_selected, event_data_filtered, by = c("SUBJID", "STUDYID"))
lm(formula = formula_value, data = anl)
})
# Plot Regression vs fitted
output$plot1 <- renderPlot({
plot(model_reactive(), which = 1)
})
# show model summary
output$text1 <- renderPrint({
model_reactive() %>% summary()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment