Skip to content

Instantly share code, notes, and snippets.

View cecilialee's full-sized avatar

Cecilia Lee cecilialee

View GitHub Profile
@cecilialee
cecilialee / modal_dialog_input_1.R
Last active November 4, 2022 01:47
Modal dialog prompt for inputs in Shiny. #r #shiny
library(shiny)
shinyApp(
ui = basicPage(
actionButton("show", "Show modal dialog"),
verbatimTextOutput("print")
),
server = function(input, output) {
@cecilialee
cecilialee / launch_webbrowser.py
Last active February 24, 2018 07:26
Launch Web browser in Python. #python #python3
import webbrowser
url = 'http://idiotinside.com'
# Open URL in new browser window
webbrowser.open_new(url) # opens in default browser
# Opens in safari browser
webbrowser.get('safari').open_new(url)
@cecilialee
cecilialee / build_xcallbackurl.py
Last active February 24, 2018 07:26
Build x-callback-url in Python. #python #python2
import urllib
import webbrowser
def build_url(app, action, action_parameter_dict):
url = '%s://x-callback-url/%s' % (app, action)
if action_parameter_dict:
par_list = []
for k, v in action_parameter_dict.items():
par_list.append(
@cecilialee
cecilialee / compare_python_r.md
Last active February 13, 2018 16:27
Compare common util functions in Python and R. #python #r

Concatenate strings

## py ##
a = 'Data Science'
b = '!'

'{}{}'.format(a, b)
#[1] 'Data Science!'
@cecilialee
cecilialee / module_1.R
Last active February 14, 2018 08:13
Simple module in Shiny. #r #shiny
# UI ==========================================================================
textModalInput = function(id) {
ns <- NS(id)
tagList(
textInput(ns("txt"), "Write something")
)
}
@cecilialee
cecilialee / scale_x_continuous.R
Last active February 14, 2018 05:27
Scale x continuous in ggplot. #r #tidyverse #ggplot
library(tidyverse)
mtcars %>%
ggplot() +
geom_point(aes(x = gear, y = wt)) +
scale_x_continuous(labels = round, breaks = 3:5)
@cecilialee
cecilialee / assign_multiple_variables.R
Last active February 19, 2018 07:04
Assign multiple variables in loop in R. #r
var_names <- paste0("p", 1:10)
values <- seq(100, 1000, by = 100)
for (i in seq_along(var_names)) assign(var_names[[i]], values[[i]])
mget(var_names)
# $p1
# [1] 100
#
# $p2
@cecilialee
cecilialee / assign_multiple_variables.py
Last active February 19, 2018 07:03
Assign multiple variables in loop in Python. #python
d = {}
for x in range(1, 10):
d["string{0}".format(x)] = "Hello"
d["string5"]
#'Hello'
d
#{'string1': 'Hello',
# 'string2': 'Hello',
@cecilialee
cecilialee / get_airtable_tables.R
Last active February 19, 2018 08:26
Get all Airtable tables with API in R. #r #jsonlite #httr
library(tidyverse)
library(httr)
library(jsonlite)
# API set up
api <- "https://api.airtable.com/v0/apphVdH23b9rXFd1p/"
api_key <- "keyL1Ja4L6pg3Uu9Q" # fake api_key
tables <- c("products", "brands", "stores")
# GET request
@cecilialee
cecilialee / unnest_dataframe.R
Created February 19, 2018 07:33
Unnest nested dataframes in R. #r
unnest_dataframes <- function(x) {
y <- do.call(data.frame, x)
if ("data.frame" %in% sapply(y, class)) unnest_dataframes(y)
y
}