Skip to content

Instantly share code, notes, and snippets.

View jcheng5's full-sized avatar

Joe Cheng jcheng5

View GitHub Profile
@jcheng5
jcheng5 / README.md
Last active March 10, 2021 16:02
Installing R-devel on Solaris 10 VM

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

item1,item2,item3,item4,item5,item6,item7,item8,item9,item10
1,1,,,1,1,,,,
,,1,1,,,1,1,,
1,,,,1,,,,1,1
,1,,1,1,,1,,1,
1,1,1,1,1,1,,,,1
,1,,,,,1,,,
,,1,1,1,1,,1,,
1,,,1,,,,1,,1
,,1,1,1,,,,1,1
@jcheng5
jcheng5 / pauseable.R
Last active July 2, 2020 12:53
Pauseable Shiny reactives
# See ?reactive for meanings of x, env, quoted, and domain.
# paused indicates the starting state of the pauseable reactive.
pauseableReactive <- function(x, env = parent.frame(), quoted = FALSE,
priority = 0, domain = shiny::getDefaultReactiveDomain(), paused = FALSE) {
shiny::installExprFunction(x, "func", eval.env = env, quoted = quoted)
vals <- shiny::reactiveValues(value = NULL)
obs <- shiny::observe(vals$value <- func(), priority = priority,
domain = domain, suspended = paused)
return(structure(
@jcheng5
jcheng5 / README.md
Last active June 26, 2020 01:08
Using a more recent version of jQuery with Shiny

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.

assign("msg", local({
i <- 0
function(url, ...) {
i <<- i + 1
on.exit(i <<- i - 1)
if (i > 1) {
message("reentrancy detected!")
return("reentrancy detected!")
}
cat("") # Calls R_ProcessEvents()
@jcheng5
jcheng5 / image_dimensions.R
Last active April 18, 2020 18:09
Determine file image size in R
jpeg_dimensions <- function(filename, bytes = 1024) {
bytes <- readBin(filename, "raw", n = bytes)
if (length(bytes) < 2 || bytes[[1]] != 0xFF || bytes[[2]] != 0xD8) {
stop("Couldn't decode jpeg")
}
ff <- which(bytes == 0xFF)
c0 <- which(bytes == 0xC0)
```{js echo=FALSE}
function enshadowGtTable(tableEl) {
var containerEl = tableEl.parentElement;
var styleEl = containerEl.previousElementSibling;
if (containerEl.tagName !== "DIV" || styleEl.tagName !== "STYLE") {
throw new Error("Unexpected document structure");
}
var shadowDiv = document.createElement("div");
shadowDiv.classList.add("gt-shadow-container");
containerEl.parentElement.insertBefore(shadowDiv, styleEl);
@jcheng5
jcheng5 / server.R
Last active January 21, 2020 20:40
Demonstration of full-height layout in Shiny. The secret is "position: absolute" and top/left/right/bottom set to 0. We'll add a layout like this to Shiny, but I want it to be way more customizable/nicer than the implementation you see here, so don't get too attached to this code :)
shinyServer(function(input, output) {
output$plot <- reactivePlot(function() {
plot(cars)
})
})
@jcheng5
jcheng5 / gist:34ef026bdefd3c9b558920b9a9804c01
Last active July 25, 2019 09:44
Solaris 10 R-devel csw
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 July 5, 2019 15:35
Celsius <=> Fahrenheit
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)