Skip to content

Instantly share code, notes, and snippets.

View jcheng5's full-sized avatar

Joe Cheng jcheng5

View GitHub Profile
@jcheng5
jcheng5 / ldaptest.js
Last active July 3, 2018 18:45
LDAP test
// Before running this script, set the LDAP_PASSWORD environment variable in
// the shell. You can do this without echoing the password by running:
//
// read -s LDAP_PASSWORD && export LDAP_PASSWORD
//
// You'll also need to modify the variable definitions at the top of this file.
// == BEGIN configuration variables ===============
var url = "ldap://adtest.rstudio.com/dc=adtest,dc=rstudio,dc=com";
@jcheng5
jcheng5 / gist:1ff1efbc539542ecedde92f25458a872
Created June 8, 2018 23:36
Cancellable tasks (without async)
base_task_iterator <- function(should_continue, iter_body) {
if (should_continue()) {
iter_body()
later::later(~base_task_iterator(should_continue, iter_body))
}
invisible()
}
while_task_iterator <- function(cancelExpr, whileExpr, func) {
http://builder.r-hub.io/file/5e5a06074fba4784a9f164e3970a2ead
@jcheng5
jcheng5 / renderui_example.R
Created April 16, 2018 18:34
freezeReactiveValue examples
library(shiny)
library(ggplot2)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("dataset", "Dataset", c("cars", "pressure", "mtcars")),
uiOutput("input_ui")
),
mainPanel(
@jcheng5
jcheng5 / dedupe.R
Created February 28, 2018 00:44
Lazy higher order reactives
library(shiny)
library(dplyr)
library(ggplot2)
dedupe <- function(r) {
x <- reactiveVal(isolate(r()))
o <- observe({
x(r())
})
@jcheng5
jcheng5 / shinymod.snippet
Last active January 22, 2019 14:09
RStudio snippet for Shiny module
snippet shinymod
${1:name}UI <- function(id) {
ns <- NS(id)
tagList(
${0}
)
}
${1:name} <- function(input, output, session) {

This snippet shows how you could use later to create an API that can be called on a background thread, to perform an arbitrary task on the main R thread, and return the result to the background thread. The background thread blocks until the result is returned from the main R thread.

@jcheng5
jcheng5 / app.R
Last active February 3, 2024 17:34
Using OAuth2 with Shiny
library(shiny)
# WARNING: This sketch does not make proper use of the "state" parameter.
# Doing so usually involves using cookies, which can be done with the
# Rook package but I have not done that here. If you choose to use this
# approach in production, please check the state parameter properly!
APP_URL <- if (interactive()) {
# This might be useful for local development. If not, just hardcode APP_URL
# to the deployed URL that you'll provide a few lines below.
@jcheng5
jcheng5 / global.R
Last active May 20, 2017 00:27
Artificially slow Shiny app for testing/debugging purposes
library(shiny)
# Configure delays using the following constants.
# before worker starts responding to listeners
STARTUP_DELAY_SECS = 0
# time to load ui.R (before first "/" response only)
UI_INIT_DELAY_SECS = 0
@jcheng5
jcheng5 / convertToSF.R
Created May 8, 2017 22:57
Convert ggfortify to sf
library(dplyr)
convertToSF <- function(df, id = "id", group = "group") {
# Extract the non-polygon data.
data <- df %>%
group_by_(id) %>%
do(head(., 1)) %>%
.[,setdiff(names(.), c("long", "lat", "order", "hole", "piece", "group"))]
# Extract the shapes. I don't know if this does the right