Last active
December 10, 2015 20:28
-
-
Save jcheng5/4487813 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
data_sets <- c("mymtcars","mtcars", "morley", "rock") | |
mymtcars <- mtcars[,1:4] |
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
<script src="https://github.com/livereload/livereload-js/raw/master/dist/livereload.js?host=localhost"></script> |
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
options(shiny.trace=TRUE, error = traceback) | |
library(shiny) | |
shinyServer(function(input, output) { | |
getdata <- reactive(function() { | |
dat <- get(input$dataset) | |
dat | |
}) | |
varnames <- reactive(function() { | |
colnames <- names(getdata()) | |
}) | |
output$choose_columns <- reactiveUI(function() { | |
if(is.null(input$dataset)) | |
return() | |
checkboxGroupInput("columns", "Choose columns", choices = varnames(), selected = varnames()) | |
}) | |
output$dataview <- reactiveTable(function() { | |
if(is.null(input$dataset) || is.null(input$columns)) | |
return() | |
dat <- getdata() | |
head(dat, 10) | |
}) | |
output$regression <- reactiveTable(function() { | |
if(is.null(input$dataset) || is.null(input$columns)) | |
return() | |
dat <- getdata() | |
colnames <- varnames() | |
if(input$addresiduals && input$tabs == 'Regression') { | |
ols <- lm(mpg ~ cyl, data = dat) | |
dat$residuals <- ols$residuals | |
} | |
head(dat, 10) | |
}) | |
}) |
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
# Define UI for miles per gallon application | |
shinyUI(pageWithSidebar( | |
headerPanel("Gist 4436657"), | |
sidebarPanel( | |
selectInput("dataset", "Data set", data_sets), | |
uiOutput("choose_columns"), | |
conditionalPanel(condition = "input.tabs == 'Regression'", | |
checkboxInput("addresiduals", "Add residuals?", value = NULL) | |
) | |
), | |
mainPanel( | |
includeHTML('lr.js'), # needed for livereload | |
tabsetPanel(id = "tabs", | |
tabPanel("Data view", tableOutput("dataview")), | |
tabPanel("Regression", tableOutput("regression")) | |
) | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment