Skip to content

Instantly share code, notes, and snippets.

Avatar

Dean Attali daattali

View GitHub Profile
@jcheng5
jcheng5 / README.md
Last active Jun 26, 2020
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.

@jimhester
jimhester / enum.R
Created Dec 4, 2017
Simple C style enum in R.
View enum.R
enum <- function(...) {
nms <- eval(substitute(alist(...)))
x <- as.list(setNames(seq_along(nms), nms))
f <- tempfile()
attach(x, name = f)
# Cleanup the enum if when the parent frame exists
# unless we are in the global environment.
if (!identical(parent.frame(), globalenv())) {
withr::defer(detach(name = f), parent.frame())
}
@hadley
hadley / shiny-oauth.r
Last active Mar 24, 2022
Sketch of shiny + oauth
View shiny-oauth.r
library(shiny)
library(httr)
# OAuth setup --------------------------------------------------------
# Most OAuth applications require that you redirect to a fixed and known
# set of URLs. Many only allow you to redirect to a single URL: if this
# is the case for, you'll need to create an app for testing with a localhost
# url, and an app for your deployed app.
@calligross
calligross / app.R
Last active Apr 7, 2022
Shiny Cookie Based Authentication Example, please visit https://calligross.de/post/using-cookie-based-authentication-with-shiny/ for more information.
View app.R
library(shiny)
library(shinyjs)
if (!dir.exists('www/')) {
dir.create('www')
}
download.file(
url = 'https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js',
destfile = 'www/js.cookie.js'
@jimhester
jimhester / 0.9.3.png
Last active Jul 11, 2018
Run R code with different versions of package dependencies, this will work in the same session as long as you don't run into issues unloading the namespaces
@daattali
daattali / rselenium-taxonomer-1-upload.R
Last active Jun 24, 2019
Use RSelenium to automatically upload many FASTQ files, submit each to "full analysis" when it's ready, and download the analyzed file on Taxonomer.com
View rselenium-taxonomer-1-upload.R
# This script uploads all the FAST files to the taxonomer server (only one file can be uploaded at a time)
# Assumes that you have RSelenium package installed and that you've got a simple selenium example to work
if (FALSE) {
fastq_files <- c(
list.files(# WHERE ARE THE FILES?, pattern = "fastq.gz$", full.names = TRUE)
)
login_password <- "" # what is my password???
library(RSelenium)
View parse_extract_html_table_w_content_preserved.R
#compare with https://gist.github.com/expersso/bb03efcab2a6c125da5ac22e1c33d070
url <- "https://github.com/daattali/addinslist/blob/master/README.md#list-of-addins"
get_html_table <- function(url){
xx <- xml2::read_html(url)
rvest::xml_node(rvest::xml_node(xx,"body"),"table")
}
tr_to_nms <- function(tbl){
@jimhester
jimhester / forks_n_commits.R
Created Apr 21, 2016
Programmatically determine forks of a repo with at least n commits. Does not try to disambiguate repeated force pushes.
View forks_n_commits.R
# Q on @GitHub: does anyone now how to easily (ie automatically) list all forks
# of a repository that have more than N commits in the fork?
library(gh) # devtools::install_github("gaborcsardi/gh")
forks_n_commits <- function(owner, repo, n = 1) {
events <- gh("GET /networks/:owner/:repo/events", owner = owner, repo = repo, .limit = Inf)
fork_pushes <- Filter(function(x) x$type == "PushEvent" && x$repo$name != paste0(owner, "/", repo),
events)
@daattali
daattali / gmailr-text.R
Last active Mar 30, 2018
Send a text message via email from R
View gmailr-text.R
library(shiny)
library(gmailr)
ui <- fluidPage(
textInput("subj", "Subject", "Schedule change"),
textInput("text", "Message"),
actionButton("btn", "Send")
)
server <- function(input, output, session) {
@lgatto
lgatto / colour-picker.R
Last active Nov 7, 2015
A simple interface to select colours
View colour-picker.R
colour_picker <- function() {
n <- length(colours())
i <- ceiling(sqrt(n))
m <- matrix(c(1:n, rep(NA, i^2 - n)),
ncol = i, nrow = i)
## plotting
image(m, col = colours(),
xaxt = "n", yaxt = "n")
k <- seq(0, 1, length.out = i)
kk <- expand.grid(k, k)