Skip to content

Instantly share code, notes, and snippets.

Joe Cheng jcheng5

Block or report user

Report or block jcheng5

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jcheng5
jcheng5 / README.md
Last active Aug 7, 2019
Installing R-devel on Solaris 10 VM
View README.md

As far as CRAN is concerned, there are two flavors of R on Solaris: one that is built using the Solaris Studio compiler, and one that is built using the GNU/gcc toolchain. The latter is far more up-to-date, but if your package requires it, then your DESCRIPTION file must declare that with the line SystemRequirements: GNU make.

These instructions are for configuring, building, and installing R-devel using the GNU/gcc toolchain (only).

You'll need VMWare Fusion on Mac, or VMWare Workstation (?) on Windows/Linux.

Get Solaris VM

Download the Solaris VM provided by Jeroen Ooms: https://github.com/jeroen/solarisvm

View gist:34ef026bdefd3c9b558920b9a9804c01
590 pkgutil -i wget
603 pkgutil -i gcc5gfortran
609 pkgutil -i -y libiconv_dev
613 pkgutil -i -y zlib_dev
615 pkgutil -i -y libz_dev
620 pkgutil -i -y liblzma_dev
622 pkgutil -i -y libpcre_dev
624 pkgutil -i -y libcurl_dev
634 pkgutil -i -y libcurl4_dev
647 pkgutil -y -i gmake
@jcheng5
jcheng5 / app.R
Created Jul 5, 2019
Celsius <=> Fahrenheit
View app.R
library(shiny)
ui <- fluidPage(
numericInput("temp_c", "Celsius", NA),
numericInput("temp_f", "Fahrenheit", NA)
)
server <- function(input, output, session) {
c_to_f <- function(c, decimals = 1) {
round((c * 9 / 5) + 32, decimals)
View leaflet-mapbox-gl.R
# BE SURE TO set your Mapbox access token with:
# options(mapbox.accessToken = "...")
library(htmltools)
library(leaflet)
mapboxgl_deps <- list(
htmlDependency(
"mapbox-gl-js", "0.53.0", c(href = "https://api.mapbox.com/mapbox-gl-js/v0.53.0/"),
script = "mapbox-gl.js",
View gist:5a90fd10eb255e978944b319ac850959
num_suffix <- function(x, base = 1000, suffixes = c("K", "M", "B", "T")) {
if (length(suffixes) == 0) {
tibble(
scale_by = rep_len(1, length(x)),
suffix = rep_len("", length(x))
)
}
i <- floor(log(abs(x), base = base))
@jcheng5
jcheng5 / addDynamicTiles.R
Created Jan 19, 2019
Leaflet dynamic tiles
View addDynamicTiles.R
library(shiny)
library(leaflet)
#' Add a tile layer whose source is an R function
#'
#' @param tileFunc A function(x, y, z) that returns a 256x256 image object
#' suitable for passing to `png::writePNG`.
#' @seealso [leaflet::addTiles()] for other parameters
addDynamicTiles <- function(map, tileFunc,
layerId = paste0("leafletRaster", sample.int(9999999, 1)),
@jcheng5
jcheng5 / 1-original.R
Created Nov 9, 2018
Simple Shiny app, with and without plot caching
View 1-original.R
library(ggplot2)
library(shiny)
ui <- fluidPage(
varSelectInput("color_by", "Color by:", diamonds, selected = "cut"),
plotOutput("plot")
)
server <- function(input, output, session) {
output$plot <- renderPlot({
@jcheng5
jcheng5 / .bashrc
Created Oct 31, 2018
Launch Shiny apps from command line
View .bashrc
# Examples:
# shiny # Launch the Shiny app in the current directory
# shiny path/to/app # Launch the Shiny app at the specified path
# shiny . launch.browser=F,port=8000 # Launch Shiny in the current dir with given options
function shiny {
R --vanilla -q -e "shiny::runApp(\"${1:-.}\", launch.browser=TRUE, $2)"
}
View selectize-tests.R
library(shiny)
bigvec <- paste0("a", 1:1e5)
named_bigvec <- setNames(bigvec, bigvec)
nested_biglist <- lapply(named_bigvec, function(item) setNames(list(item), item))
test_set <- list(
"Unnamed vector" = c(1, 2),
"Named vector" = c(a = 1, B = 2),
"Partially named vector" = c(a = 1, B = 2, 3),
@jcheng5
jcheng5 / README.md
Last active Sep 18, 2018
Using a more recent version of jQuery with Shiny
View README.md

To opt into a more recent version of jQuery, you can add an htmlDependency object pointing to your desired version, somewhere (anywhere) in your UI:

htmltools::htmlDependency("jquery", "3.3.1",
  src = c(href = "https://code.jquery.com/"),
  script = "jquery-3.3.1.min.js")

This example will serve jQuery 3.3.1 from the jQuery CDN. If your app needs to work with clients that won't be able to connect to the wider internet, you'll need to download the jquery-3.3.1.min.js file, put it in an app subdirectory (say, jquery), and point to the directory using the src argument.

You can’t perform that action at this time.