Skip to content

Instantly share code, notes, and snippets.

library(tidyverse) # for the plot only
# required librariers that need to be installed (not loaded!): quantmod, dplyr, tibble 
# (the latter two are in the tidyverse anyway)

#' Downloads stock data from yahoo finance etc. using quantmod::getSymbols
#' 
#' @param tickers a vector of tickers
#' @param from start date
#' @param to end date
@DavZim
DavZim / Readme.md
Last active February 13, 2020 09:08
Simple explanation how to use git-hooks to automatically deploy your code to production

How to Deploy git to a Server using git-hooks

The following script outlines how we can use git-hooks for continuous deployment (when you push your git repository, it will automatically be deployed to the server).

Note, this script is heavily based on but slightly extends this gist, see also this explanation.

Basic idea: using git-hooks to copy the files on a target machine from a remote git repository to a specific target location.

For this, we need multiple components:

  • On the target machine (the production server)
@DavZim
DavZim / hash_example.md
Last active April 22, 2020 13:03
Hashing tidymodels workflows
library(tidymodels)
#> ── Attaching packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidymodels 0.1.0 ──
#> ✓ broom     0.5.5     ✓ recipes   0.1.9
#> ✓ dials     0.0.4     ✓ rsample   0.0.5
#> ✓ dplyr     0.8.5     ✓ tibble    2.1.3
#> ✓ ggplot2   3.3.0     ✓ tune      0.0.1
#> ✓ infer     0.5.1     ✓ workflows 0.1.1
#> ✓ parsnip   0.0.5     ✓ yardstick 0.0.6
#> ✓ purrr     0.3.3
@DavZim
DavZim / app.R
Last active June 18, 2020 11:02
Asynchronous Shiny App
library(shiny)
library(promises)
library(future)
plan(multiprocess)
long_running_function <- function(sleep = 3) {
Sys.sleep(sleep)
"Finished long_running_function()"
}
library(shinydashboard)
library(rintrojs)
add_class <- function(x, class) {
x$attribs <- append(x$attribs, list(class = class))
x
}
# # Alternatively, override the functions of shiny/shinydashboard
# menuItem <- function(text, tabName, ...) {
``` r
library(shiny)
library(magrittr) # for the pipe
library(shinydashboard)
#>
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#>
#> box
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.1.2, PROJ 7.0.0
library(leaflet)
library(leafem)

url <- "https://raw.githubusercontent.com/bjornharrtell/flatgeobuf/3.0.1/test/data/UScounties.fgb"
map <- st_read(url)
#> Reading layer `UScounties' from data source `https://raw.githubusercontent.com/bjornharrtell/flatgeobuf/3.0.1/test/data/UScounties.fgb' using driver `FlatGeobuf'
#&gt; Simple feature collection with 3221 features and 6 fields
@DavZim
DavZim / 01-app-plain.R
Last active August 26, 2020 16:12
Shiny Modules Test
library(shiny)
library(tidyverse)
library(glue)
library(DT)
df <- mtcars %>%
rownames_to_column("car") %>%
select(car, everything())
@DavZim
DavZim / map_projections.R
Created January 20, 2021 10:37
Creates a gif of the world in different map projections
library(tidyverse)
library(sf)
library(spData)
library(gganimate)
data(world)
# see also: https://proj.org/operations/projections/index.html
projs <- list(
"Mercator" = "+proj=merc",
@DavZim
DavZim / TailwindCSS Shiny Modal.R
Created August 12, 2022 20:42
Showcases how to create a Modal in R shiny with Tailwind CSS
library(shiny)
library(shiny.tailwind)
# Define Helper functions for open modal btn and modal =====
#' Creates a button to open a Modal Dialog
#'
#' @param btn_id ID of the button
#' @param btn_label Label for the button
#' @param btn_class Classes to style the button