Skip to content

Instantly share code, notes, and snippets.

View jbryer's full-sized avatar

Jason Bryer jbryer

View GitHub Profile
@jbryer
jbryer / Login.r
Created January 26, 2024 03:44
Shiny authentication
# This script is modified by Jason Bryer (jason@bryer.org) from Huidong Tian's
# original script. The blog post describing the method is here:
# http://withr.me/authentication-of-shiny-server-application-using-a-simple-method/
# The original R script is located here: https://gist.github.com/withr/9001831
#
# This script adds two new features: 1. Render a logout button, and 2. provide
# the ability for visitors to create a new account.
#
# Within your server.R file, be sure to use: source('Login.R', local=TRUE)
#
@jbryer
jbryer / 2013-08-B.txt
Created February 21, 2016 18:14
ShinyAssessmentTest
From San Francisco to New York to Paris, city governments, high-class restaurants,
schools, and religious groups are ditching bottled water in favor of what comes out of the
faucet. With people no longer content to pay 1,000 times as much for bottled water, a
product no better than water from the tap, a backlash against bottled water is growing.
(5) The U.S. Conference of Mayors, which represents some 1,100 American cities,
discussed at its June 2007 meeting the irony of purchasing bottled water for city employees
and for city functions while at the same time touting1 the quality of municipal water. The
group passed a resolution sponsored by Mayors Gavin Newsom of San Francisco, Rocky
Anderson of Salt Lake City, and R. T. Rybak of Minneapolis that called for the examination
(10) of bottled water’s environmental impact. The resolution noted that with $43 billion a year
@jbryer
jbryer / strtable.R
Last active December 21, 2023 21:36
Implementation of the str function to return a data.frame
#' Creates a \code{data.frame} version of the str function for data.frames.
#'
#' Note that this function only works with \code{data.frames}. The function
#' will throw an error for any other object types.
#'
#' @param n the first n element to show
#' @param width maximum width in characters for the examples to show
#' @param n.levels the first n levels of a factor to show.
#' @param width.levels maximum width in characters for the number of levels to show.
#' @param factor.values function defining how factor examples should be printed.
@jbryer
jbryer / parse.codebook.r
Last active March 9, 2023 15:19
Parses a codebook file where lines starting at column zero (far left) represet variable information (e.g. name, description, type) and indented lines (i.e. lines beginning with white space, either tabs or spaces, etc.) represent factor levels and labels.
#' Parse a codebook file with variable and level information.
#'
#' Parses a codebook file where lines starting at column zero (far left) represet
#' variable information (e.g. name, description, type) and indented lines
#' (i.e. lines beginning with white space, either tabs or spaces, etc.) represent factor
#' levels and labels.
#'
#' Note that white space at the beginning and end of each line is stripped before
#' processing that line.
#'
@jbryer
jbryer / gitbook.R
Last active February 1, 2023 09:07
Functions to work with Gitbook.io and R Markdown
require(knitr)
#' Initializes a new Gitbook.
#'
#' This will initalize a new Gitbook in the given directory. When done, it will
#' also change the working directory.
#'
#' @author Jason Bryer <jason@bryer.org>
newGitbook <- function(dir) {
.Deprecated('This function has been moved to the gitbook R package. See http://jason.bryer.org/Rgitbook for more information')
@jbryer
jbryer / app.R
Last active February 28, 2022 15:51
Framework for running Shiny Applications from R packages with parameters passed to the application. See this blog post for more information: https://bryer.org/post/2021-02-12-shiny_apps_in_r_packages/
# Run the App on a Shiny Server
library(shiny)
source('shiny_param_test.R')
shiny::shinyApp(ui = shiny_ui,
server = shiny_server)
@jbryer
jbryer / package.R
Last active January 16, 2022 06:31
#' Simplified loading and installing of packages
#'
#' This is a wrapper to \code{\link{require}} and \code{\link{install.packages}}.
#' Specifically, this will first try to load the package(s) and if not found
#' it will install then load the packages. Additionally, if the
#' \code{update=TRUE} parameter is specified it will check the currently
#' installed package version with what is available on CRAN (or mirror) and
#' install the newer version.
#'
#' @param pkgs a character vector with the names of the packages to load.
library(tidyverse)
library(reshape2)
library(lubridate)
library(rnoaa)
token <- '' # Get token here: https://www.ncdc.noaa.gov//cdo-web/token
options(noaakey = token)
marathon_dates <- c('2021-01-10','2020-01-12','2019-01-13',
'2018-01-07','2017-01-08','2016-01-10','2015-01-11','2014-01-12',
@jbryer
jbryer / setup.r
Created March 7, 2012 16:14
R Setup Script
#List of most used R packages that we wish to install.
libraries = c('cacheSweave', 'Deducer', 'devtools', 'doBy', 'foreign', 'gdata',
'ggplot2', 'Hmisc', 'JGR', 'lubridate', 'maps', 'mapdata', 'mapproj',
'maptools', 'proto', 'psych', 'R2wd', 'RCurl', 'reshape',
'RODBC', 'roxygen2', 'seqinr', 'sm', 'sp', 'sqldf', 'survey',
'WriteXLS', 'XML', 'xtable')
#We will install packages from the main CRAN site
repos = 'http://cran.r-project.org'
#Site provides some prebuilt binaries for Windows
@jbryer
jbryer / xtable.decimal.r
Last active November 21, 2020 19:51
Prints a LaTeX table with numeric columns aligned on their decimal points. This function wraps the xtable and print.xtable functions in the xtable package so that numeric columns are aligned on their decimal place.
require(xtable)
#' Prints a LaTeX table with numeric columns aligned on their decimal points.
#'
#' This function wraps the \code{\link{xtable}} and \code{\link{print.xtable}}
#' functions in the \code{xtable} package so that numeric columns are aligned
#' on their decimal place.
#'
#' See \url{http://jason.bryer.org/posts/2013-01-04/xtable_with_aligned_decimals.html}
#' for more information.