Skip to content

Instantly share code, notes, and snippets.

View mxblsdl's full-sized avatar
🦊
Focusing

Max Blasdel mxblsdl

🦊
Focusing
View GitHub Profile
@mxblsdl
mxblsdl / git prompt
Created September 12, 2020 21:03
set your prompt to display the current git branch. Should be added to the .Rprofile file
if(requireNamespace("prompt", quietly = T)) {
prompt_git <- function(...) {
paste0(
"[", prompt::prompt_git(), "]", "> "
)
}
prompt::set_prompt(prompt_git)
rm(prompt_git)
}
switch (
menu(choices = c("base", "mid", "DC"), graphics = T, title = "DC Charging Scenario"),
"base",
"mid",
"DC"
)
@mxblsdl
mxblsdl / dual_axis.R
Created April 2, 2021 17:34
Plot two different axis in ggplot
# set the limits of each axis
# these will need to be changed for each data
# use summary(df) to get metrics
ylim_prime <- c(0.35, 0.76)
ylim_sec <- c(6200, 12000)
# calculate values for use in plot
b <- diff(ylim_prime)/diff(ylim_sec)
a <- ylim_prime[1] - b*ylim_sec[1]
@mxblsdl
mxblsdl / jbox.R
Last active June 18, 2022 15:34
Example of using jbox with shiny
# UI
tags$script(
src = paste0(
"https://cdn.jsdelivr.net/gh/StephanWagner/",
"[email protected]/dist/jBox.all.min.js"
)
),
tags$link(
rel = "stylesheet",
@mxblsdl
mxblsdl / close_connections.R
Created June 18, 2022 15:35
Example of callback function for when shiny closes
# Close connection to database when app closes
cancel.onSessionEnded <- session$onSessionEnded(function() {
if(exists("con")){
dbDisconnect(con)
print("Connection to DB Closed")
}
})