Last active
February 26, 2016 18:58
-
-
Save dpastoor/3ec36c38b27db22f50e1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| library(MASS) | |
| library(shiny) | |
| library(mrgsolve) | |
| library(dplyr) | |
| library(magrittr) | |
| library(parallel) | |
| RNGkind("L'Ecuyer-CMRG") | |
| set.seed(101) | |
| mc.reset.stream() | |
| outside_var <- "outside" | |
| seed <- "global_seed" | |
| ##' UI ########################################### | |
| ui<- fluidPage( | |
| titlePanel("Shiny MC"), | |
| sidebarLayout( | |
| sidebarPanel( | |
| sliderInput("OM1", "OMEGA 1",0,4,1,0.25), | |
| sliderInput("OM2", "OMEGA 2",0,4,1,.25), | |
| sliderInput("n", "N rep", 1,100,10,1), | |
| sliderInput("N", "N subj", 1, 100,10,1), | |
| sliderInput("mccores", "mc.cores", 1,4,2,1) | |
| ), | |
| mainPanel(tableOutput("table") | |
| ) | |
| ) | |
| ) | |
| ##' Simulate | |
| ##' if(fix) the seed will be set based on replicate number | |
| sim <- function(i,N,om1,om2) { | |
| inside_var <- "inside_sim" | |
| inside_func <- function(){ | |
| completely_inside <- "completely_inside" | |
| data.frame(i, N, om1, om2, outside_var, inside_var, completely_inside, seed) | |
| } | |
| return(inside_func()) | |
| } | |
| ##' Summarize simulations | |
| smry <- function(x) { | |
| x %>% summarise(nETA1 = n_distinct(ETA1), | |
| vETA1 = var(ETA1), | |
| sETA1 = sum(ETA1), | |
| nETA2 = n_distinct(ETA2), | |
| vETA2 = var(ETA2), | |
| sETA2 = sum(ETA2), | |
| n=n()) | |
| } | |
| ##' SERVER ########################################### | |
| server<-function(input, output) { | |
| output$table <- renderTable({ | |
| seed <- "server_seed" | |
| mclapply(1:input$n, | |
| mc.cores=input$mccores, | |
| sim,input$N,input$OM1,input$OM2) %>% bind_rows | |
| }) | |
| } | |
| ##' Run the shiny app | |
| shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment