Created
January 7, 2013 17:44
-
-
Save jcheng5/4476910 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
<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
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<script src="http://aleph.sagemath.org/static/jquery.min.js"></script> | |
<script src="http://aleph.sagemath.org/static/embedded_sagecell.js"></script> | |
<script> | |
$(function () { | |
sagecell.makeSagecell({inputLocation: 'div.compute-r', | |
evalButtonText: 'Evaluate', | |
defaultLanguage: "r", | |
languages: sagecell.allLanguages}); | |
}); | |
</script> | |
<div class="compute-r"><script type="text/x-sage"> | |
x <- 3 | |
x <- x + 3 | |
print(x) | |
</script></div> |
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) | |
shinyServer(function(input, output) { | |
data_sets <- c("mymtcars","mtcars", "morley", "rock") | |
mymtcars <- mtcars[,1:4] | |
varnames <- function() { | |
if(is.null(input$dataset)) return() | |
dat <- get(input$dataset) | |
colnames <- names(dat) | |
return(colnames) | |
} | |
# if varnames is reactive only the data changes but the list of variable | |
# names is not updated | |
# varnames <- reactive(varnames) | |
changedata <- function() { | |
dat <- get(input$dataset) | |
dat[,1] <- NULL | |
assign(input$dataset, dat, inherits = TRUE) | |
# `<<-`('mymtcars', dat) # this works | |
# `<<-`(input$dataset, dat) # this doesn't | |
return() | |
} | |
# test | |
changedata <- reactive(changedata) | |
# Drop-down selection box for which data set | |
output$choose_dataset <- reactiveUI(function() { | |
selectInput("dataset", "Data set", data_sets) | |
}) | |
# Check boxes | |
output$choose_columns <- reactiveUI(function() { | |
if(is.null(input$dataset)) | |
return() | |
colnames <- varnames() | |
# Create the checkboxes and select them all by default | |
checkboxGroupInput("columns", "Choose columns", choices = colnames, selected = colnames) | |
}) | |
output$data1 <- reactiveText(function() { | |
if(is.null(input$dataset) || is.null(input$columns)) | |
return() | |
# if the changedata function is called here the data are updated | |
# but input_columns is not | |
# print(varnames()) | |
# changedata() | |
# print(varnames()) | |
# Get the data set | |
dat <- get(input$dataset) | |
# head(dat, 2) | |
str(dat[1:2,]) | |
}) | |
# output$data2 <- reactiveTable(function() { | |
output$data2 <- reactiveText(function() { | |
if(is.null(input$dataset) || is.null(input$columns)) | |
return() | |
# varnames are only updated if the varnames function is not reactive | |
# data is changed for display in the data2 tab but not for data1 tab | |
print(varnames()) | |
changedata() | |
print(varnames()) | |
# Get the data set | |
dat <- get(input$dataset) | |
# head(dat, 2) | |
str(dat[1:2,]) | |
}) | |
}) |
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( | |
uiOutput("choose_dataset"), | |
uiOutput("choose_columns") | |
), | |
mainPanel( | |
includeHTML('lr.js'), # needed for livereload | |
tabsetPanel(id = "analysistabs", | |
tabPanel("Data1", verbatimTextOutput("data1")), | |
tabPanel("Data2", verbatimTextOutput("data2")), | |
tabPanel("Sage", includeHTML('sage.js')) | |
) | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment