Skip to content

Instantly share code, notes, and snippets.

View zappingseb's full-sized avatar
🏠
Working from home

Sebastian Engel-Wolf zappingseb

🏠
Working from home
View GitHub Profile
@zappingseb
zappingseb / app.R
Created February 11, 2020 14:13
Nested shiny modules
# This is an example app to understand how nested shiny modules are
# working and what is the general principle
library(shiny)
# Inner Module representing a widget
# that contains of UI rendered parts (text2)
# and server rendered parts (text1)
ui_inner <- function(id, text2) {
ns <- NS(id)
@zappingseb
zappingseb / DockerFile
Last active October 3, 2019 20:19
DockerFile for Mt Whitney crawl
# alpine-python-ecmwfapi
FROM rocker/tidyverse:3.6.0
MAINTAINER zappingseb "sebastian@mail-wolf.de"
RUN R -e "install.packages(c('RSelenium'), repos='https://cran.rstudio.com/') "
RUN apt-get update -qq \
&& apt-get install -y \
python-pip \
vim
# 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"))
observeEvent(input$show_r_code, {
showModal(modalDialog(
title = "R Code",
tags$pre(
id = "r_code",
expandChain(
library_code,
data_code,
output$plot1(),
output$text1()
# Plot Regression vs fitted
output$plot1 <- metaRender(renderPlot, {
plot(!!model_reactive(), which = 1)
})
# show model summary
output$text1 <- metaRender(renderPrint, {
!!model_reactive() %>% summary()
})
# 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(bindToReturn = TRUE, {
model_data <- !!data_set_reactive()
lm(formula = !!formula_reactive(), data = model_data)
})
})
formula_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))
rlang::new_formula(rlang::sym("AVAL"), regressors)
})
@zappingseb
zappingseb / data_set_reactive.R
Created July 16, 2019 07:53
Data set reactive
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"))
})
@zappingseb
zappingseb / data_code.R
Created July 16, 2019 07:39
Data code for reproducible app
data_code <- quote({
# Patient listing
pat_data <- ...
# Days where Overall Survival (OS), Event free survival (EFS) and Progression Free Survival (PFS) happened
event_data <- ...
})
eval(data_code)
@zappingseb
zappingseb / serverfunction.R
Last active July 16, 2019 21:27
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"))))