Skip to content

Instantly share code, notes, and snippets.

View cecilialee's full-sized avatar

Cecilia Lee cecilialee

View GitHub Profile
@cecilialee
cecilialee / insert_dynamic_n_ui.R
Last active February 24, 2018 07:26
Render dynamic number of UI in Shiny (all codes in server side). #r #shiny
library(shiny)
ui = basicPage(
# inputs
textInput("txt", "Text"),
numericInput("n", "Number", 1),
actionButton("submit", "Submit"),
# outputs
uiOutput("ui")
)
@cecilialee
cecilialee / brushing_plots.R
Last active February 24, 2018 07:26
Select rows from plot with brush and hover in Shiny. #r #shiny
# Load packages
library(shiny)
library(ggplot2)
library(tidyverse)
library(DT)
# Load data
load(url("http://s3.amazonaws.com/assets.datacamp.com/production/course_4850/datasets/movies.Rdata"))
# Define UI for application that plots features of movies
@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 / filter_datatable_download_shiny.R
Created February 24, 2018 03:44
Filter datatable columns with download option in Shiny. #r #shiny
library(shiny)
library(dplyr)
library(readr)
load(url("http://s3.amazonaws.com/assets.datacamp.com/production/course_4850/datasets/movies.Rdata"))
# UI
ui <- fluidPage(
sidebarLayout(
# Input(s)
@cecilialee
cecilialee / download_files_shiny.R
Created February 24, 2018 03:26
Download files function in Shiny. #r #shiny
library(shiny)
library(dplyr)
library(readr)
load(url("http://s3.amazonaws.com/assets.datacamp.com/production/course_4850/datasets/movies.Rdata"))
# UI
ui <- fluidPage(
sidebarLayout(
# Input(s)
@cecilialee
cecilialee / multiple_line_string.R
Created February 24, 2018 03:17
Render string in multiple lines using HTML in Shiny. #r #shiny
library(shiny)
ui = basicPage(
textInput("txt1", "Input the first string"),
textInput("txt2", "Input the second string"),
uiOutput("cat_str")
)
server = function(input, output) {
@cecilialee
cecilialee / selectize_multiple_app.R
Created February 24, 2018 02:32
Selectize and multiple selectInput in Shiny. #r #shiny
library(shiny)
library(ggplot2)
library(dplyr)
library(DT)
load(url("http://s3.amazonaws.com/assets.datacamp.com/production/course_4850/datasets/movies.Rdata"))
all_studios <- sort(unique(movies$studio))
# UI
ui <- fluidPage(
sidebarLayout(
@cecilialee
cecilialee / dc_ui.R
Created February 23, 2018 09:08
Create a division in ui.R showing one dc chart in dcr. #r #shiny #dcr
library(shiny)
library(dcr)
ui = fluidPage(
chartOutput("plot"),
fluidRow(column(6, dc_ui("chart1", text = "cyl",
show_filter = TRUE,
reset_text = TRUE)),
column(6, dc_ui("chart2", text = "gear by carb",
show_filter = TRUE,
@cecilialee
cecilialee / use_dc_code_dcr.R
Last active February 23, 2018 08:08
Use dc.js code directly in dcr. #r #shiny #dcr
library(dcr)
dcr <- dcr(mtcars)
chart <- dcrchart(type = "rowChart", id = "chart1", dimension = "cyl",
reduce = reduceCount(), width = 400, height = 250,
colors = dc_code("d3.scale.category10()"))
dcr + chart