Skip to content

Instantly share code, notes, and snippets.

ui <- fluidPage(
tags$script('
Shiny.addCustomMessageHandler("toggleWellPanel",
function(message) {
document.getElementById(message["id"]).style.display = message["status"];
}
);
'),
fileInput('file', 'File'),
selectInput('col_select', 'Columns', choices=c(''), multiple=TRUE),
ui <- fluidPage(
fileInput('file', 'File'),
selectInput('col_select', 'Columns', choices=c(''), multiple=TRUE),
wellPanel(uiOutput('wellpanels'))
)
server <- function(input, output, session) {
data <- reactive({
f <- input$file
@mplourde
mplourde / gist:66322522df1001f218dd
Created May 30, 2014 18:24
plotting multiple ggplots in one window
library(grid)
plot1 <- ggplot(data.frame(x=1:10, y=1:10), aes(x=x, y=y)) + geom_point()
plot2 <- plot1
plot3 <- plot1
nrow <- 1
ncol <- 3
vp <- viewport(layout=grid.layout(nrow, ncol))
@mplourde
mplourde / gist:a75ea54db4f7209b58b9
Created June 3, 2014 13:33
using the R layout command
layout.mat <- matrix(c(1,1,1,1,1,1,2,3,3), nrow=3)
layout.mat
layout(layout.mat)
plot(1:10)
plot(1:10)
@mplourde
mplourde / gist:05af18f121fa416d2f38
Created June 10, 2014 18:20
multiple lines in ggplot
library(ggplot2)
library(reshape2) # gives you the melt function
d1 <- data.frame(time=1:10, x1=1:10)
d2 <- data.frame(time=1:10, x2=1:10/2)
d <- merge(d1, d2, by='time')
d.molten <- melt(d, id.var='time')
@mplourde
mplourde / gist:153f021018e361315916
Last active August 29, 2015 14:02
building a data.frame column wise
num.cols <- 10
# allocate space for your ten columns
cols <- vector('list', num.cols)
# add key column, such as timestamp
cols[[1]] <- 1:5
for (i in 2:num.cols) {
cols[[i]] <- rnorm(5) # add the next column, 5 random numbers
@mplourde
mplourde / plotly snippets
Created August 1, 2014 15:20
connecting R to plotly
options(RCurlOptions=list(proxy='web.proxy.com:8080'))
py <- plotly("me", "mec3g0e1z7")
p <- ggplot(mtcars, aes(x=mpg, y=cyl)) + geom_point()
res <- py$ggplotly(k, kwargs=list(auto_open=FALSE))
@mplourde
mplourde / shiny url variables
Created August 14, 2014 14:13
controlling shiny app page with URL variables
ui <- navbarPage('TEST', id='page', collapsable=TRUE, inverse=FALSE,
# define a message handler that will receive the variables on the client side
# from the server and update the page accordingly.
tags$head(tags$script("
Shiny.addCustomMessageHandler('updateSelections',
function(data) {
var nav_ref = '#page a:contains(\"' + data.nav + '\")';
var tabpanel_id = data.nav == 'Alpha' ? '#alpha_tabs' : '#beta_tabs';
var tab_ref = tabpanel_id + ' a:contains(\"' + data.tab + '\")';
$(nav_ref).tab('show');
options(shiny.reactlog=TRUE, warn=2, show.error.locations=TRUE, error=recover)
# interactive session
browser()
# print message
message('message')
# error handling
err.hanlder <- function(e) message(e)
## R
# install possible missing dependencies for R packages
apt-get -y install libcurl4-gnutls-dev
apt-get -y install libcairo2-dev
apt-get -y install libgdal1-dev libproj-dev
apt-get -y install libxt-dev
apt-get -y install libiodbc2 libiodbc2-dev
apt-get -y install libgdal-dev libproj-dev
# then install these packages
shiny # devtools::install_github('shiny', 'rstudio')