Skip to content

Instantly share code, notes, and snippets.

@DavZim
DavZim / plumber.R
Created January 15, 2024 22:20
R Plumber + HTMX
#* @assets ./public /
list()
n_clicked <- 0
#* @post /clicked
#* @serializer html
function() {
n_clicked <<- n_clicked + 1
paste0("Clicked <b>", n_clicked, "</b>\n")
}

First attempt using import version

setwd("~/projects/Github/")
packageVersion("import")
#> [1] ‘1.3.0.9004’

if (dir.exists("pkgs")) unlink("pkgs", recursive = TRUE)

dir.create("pkgs")
dir.create("pkgs/0.1.0")
@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
@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 / 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())
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
``` r
library(shiny)
library(magrittr) # for the pipe
library(shinydashboard)
#>
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#>
#> box
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, ...) {
@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()"
}
@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