Skip to content

Instantly share code, notes, and snippets.

View cecilialee's full-sized avatar

Cecilia Lee cecilialee

View GitHub Profile
@cecilialee
cecilialee / colored_icons_shiny.R
Last active March 23, 2018 09:51
Use colors on icons in Shiny. #r #shiny
library(shiny)
library(DT)
library(dplyr)
ui <- basicPage(
tags$style(".glyphicon-ok-sign {color:#2b8ee5}
.glyphicon-question-sign {color:#f4e107}
.glyphicon-exclamation-sign {color:#e5413b}
.glyphicon-flag, .glyphicon-trash {color:#28b728}"),
DT::dataTableOutput("table")
@cecilialee
cecilialee / condition_actions_app.R
Created March 19, 2018 10:11
Conditional actions in Shiny. #r #shiny
library(shiny)
library(shinyjs)
source("module.R")
# UI ==========================================================================
ui <- fluidPage(
useShinyjs(),
radioButtons("mode", "Mode",
choices = c("Entry" = "entry",
"Validation" = "validation"),
@cecilialee
cecilialee / parse_quoted_na.R
Created March 14, 2018 08:38
Parse quoted "NA" to NA in R. #r
df <- replace(df, df == "NA", NA)
@cecilialee
cecilialee / filter_row_contains_certain_string.R
Last active March 6, 2018 02:30
Filtering row which contains a certain string using dplyr in R. #r
library(dplyr)
iris %>% filter(grepl("se", Species))
@cecilialee
cecilialee / separate_column_to_columns.R
Last active March 2, 2018 22:57
Separate one column into multiple columns in R. #r #tidyr
library(tidyr)
library(dplyr)
df <- data.frame(x = c(NA, "a|b", "a|d", "b|c"))
df %>% separate(x, c("word1", "word2"))
@cecilialee
cecilialee / summary_to_df.R
Created March 2, 2018 12:24
Turn summary statistics to tidy data frame in R. #r
library(broom)
tidy(glimpse(mtcars))
@cecilialee
cecilialee / run_shiny_in_terminal
Created March 2, 2018 07:56
Run Shiny in terminal. #r #shiny
Rscript -e "shiny::runApp('poldata_app.R')"
@cecilialee
cecilialee / import_csv_to_sqlite.R
Created March 2, 2018 06:57
Import CSV to Sqlite with sqldf in R. #r
# create a test file
write.table(iris, "iris.csv", sep = ",", quote = FALSE, row.names = FALSE)
# create an empty database.
# can skip this step if database already exists.
sqldf("attach testingdb as new")
# or: cat(file = "testingdb")
# read into table called iris in the testingdb sqlite database
library(sqldf)
@cecilialee
cecilialee / hide_show_conditional_panel.R
Last active February 24, 2018 08:19
Hide and show elements in Shiny. #r #shiny
# hide and show elements using conditional panel
library(shiny)
ui = basicPage(
checkboxInput("show", "Show datatable",
value = FALSE),
conditionalPanel("input.show == true",
dataTableOutput("mtcars"))
)
@cecilialee
cecilialee / tabset_panel.R
Created February 24, 2018 07:45
Tabset panel in Shiny. #r #shiny
library(shiny)
library(dplyr)
library(ggplot2)
ui = fluidPage(
tabsetPanel(
tabPanel("Plot",
plotOutput("my_plot")
),
tabPanel("Data",