Skip to content

Instantly share code, notes, and snippets.

View steve-liang's full-sized avatar

daboliang steve-liang

  • San Diego, CA
View GitHub Profile
@steve-liang
steve-liang / gitcom.md
Created May 6, 2020 02:17 — forked from jednano/gitcom.md
Common git commands in a day-to-day workflow

Git Cheat Sheet

Initial Setup

Create an empty git repo or reinitialize an existing one

$ git init
@steve-liang
steve-liang / ggplot_tooltip.R
Created December 5, 2019 16:55
ggplot2 can have tooltip with Shiny (Thanks to origin: https://gitlab.com/snippets/16220)
library("shiny")
library("ggplot2")
ui <- pageWithSidebar(
headerPanel("Tooltips in ggplot2 + shiny"),
sidebarPanel(
HTML("Tooltips are managed by combination of shiny+ggplot hover functionality",
"and css styles. By setting hover argument of 'plotOutput' we could access",
"hover data from the server side, as an ordinary input. Hover input is",
@steve-liang
steve-liang / benchmarking_iterations.R
Created August 16, 2019 03:47
benchmarking for loop, sapply/lapply and purrr:map()
library(nycflights13)
library(microbenchmark)
library(dplyr)
library(tidyr)
library(purrr)
data <- flights
for_loop <- microbenchmark::microbenchmark(times = 1, {
carriers <- unique(data$carrier)
@steve-liang
steve-liang / dynamic_rmd_code_chunk.Rmd
Created July 12, 2019 02:21
Using loop to generate Code Chunks
---
title: "Dynamic R Markdown Code Chunk"
output:
html_document:
theme: united
params:
insights: "NA"
---
```{r setup, echo=FALSE}
@steve-liang
steve-liang / dynamic_ui_module.R
Created July 9, 2019 22:51
building dynamic UI with shiny module
library(shiny)
library(dplyr)
library(ggplot2)
library(noteMD)
########################################
# ui and server functions for the module
########################################
commInsightInput <- function(id){
ns <- NS(id)
@steve-liang
steve-liang / gist:31597d8c909f923e2c4fc3f9dcb56b57
Last active July 7, 2019 20:03
Gist for Twitter's Troubleshooting substitute() vs. enquo()
my_summarise() is a custom function that automatically choose between sym() and enquo() for input type "character" and ^quosure
## This works!
my_summarise <- function(df, var){
if(inherits(substitute(var), "character")){
var = sym(var)
}
else if(inherits(substitute(var), "name")){
var = enquo(var)
}
# robosat workflow to classify buildings in rutland, vt:
# (to check on any file locally in this process):
# docker cp <IMAGE_ID>:/app/<filename> .
docker pull mapbox/robosat:latest-cpu
docker run -i -t mapbox/robosat:latest-cpu /bin/bash
# configure some things
apt-get update && apt-get install -y sudo && rm -rf /var/lib/apt/lists/*
@steve-liang
steve-liang / sci_ubuntu_setup.sh
Created December 9, 2018 22:36 — forked from anhqle/sci_ubuntu_setup.sh
A shell script to install common scientific / programming tools on Ubuntu
#!/bin/bash
# Marwick Lab Computational Environment Setup (Anh's version)
# this script can be run from the terminal with the next line (minus the #)
# bash install_things.sh
# you will need to enter your password at a few points, so keep an eye on it while it runs.
# in case we need to step through:
############################################################################################
# Benchmark fst against saveRDS, fread/fwrite, and feather #
############################################################################################
# get data.table dev version from GitHub (multithreaded):
# install.packages("data.table", type = "source", repos = "http://Rdatatable.github.io/data.table")
require(fst) # v0.7.2
require(data.table) # dev version v1.10.5 (2017/4/14)
@steve-liang
steve-liang / manage_users_with_encryption.R
Created November 6, 2017 17:22 — forked from harveyl888/manage_users_with_encryption.R
Manage users with encryption (R Shiny App)
## Authentication
## This is a small app to demonstrate user-managed authentication using a hash to encode passwords.
## Users are stored in a SQL database with passwords along with roles.
## Once a user is logged in the shiny app responds to the user's role.
## In order to use in a real setting, additional code for password management,
## changing and resetting would need to be implemented.
library(shiny)
library(RSQLite)
library(sodium)