Skip to content

Instantly share code, notes, and snippets.

@johndrummond
johndrummond / JWTDemo.R
Last active August 29, 2019 16:28
Essentially the code from the example on https://cran.r-project.org/web/packages/jose/vignettes/jwt.html to remember the location and show lists
#example from https://cran.r-project.org/web/packages/jose/vignettes/jwt.html
# check against https://jwt.io/
# and showing arrays work
library(openssl)
library(jose)
# Example payload
claim <- jwt_claim(user = "jeroen", session_key = 123456,
groups = c("fred", "tom", "jane"),
@johndrummond
johndrummond / Show.shiny.headers.R
Created August 14, 2019 09:42
show shiny http headers
#
# This is a Shiny web application. samples of the headers
library(shiny)
library(stringr)
# Define UI
ui <- pageWithSidebar(
headerPanel("Shiny Client Data"),
# samples of some joins of data.tables with trivial tables
library(data.table)
dt1 <- data.table(f1=1:5, f2=sample(letters,5))
dt2 <- data.table(f1=2:6, f3=sample(letters,5))
dt3 <- data.table(f1=c(2,2:6), f3=sample(letters,6))
dt1
dt2
dt3
@johndrummond
johndrummond / shiny.router.dummy.R
Created August 5, 2019 22:50
sample shiny router app returning json but wrapped in websocket and html
# This was an attempt to return json on /health/ with shiny.router
# https://appsilon.com/shiny-router-package/
# trying https://stackoverflow.com/users/7268834/slavakx 's suggestion
# https://stackoverflow.com/questions/19991654/shiny-server-print-json-as-a-result-output
# but the json is already wrapped
library(shiny)
library(shiny.router)
library(data.table)
library(jsonlite)
@johndrummond
johndrummond / shiny_dummy_json_health.R
Created August 5, 2019 22:44
demo shiny server app with health handler returning plain json on health path
#
# This is a Shiny web application.
# with a handler that returns plain json
# run and in a browser look for /health/
# e.g. http://127.0.0.1:5732/health/
# from https://stackoverflow.com/users/1455889/amaurel
# on https://stackoverflow.com/questions/19991654/shiny-server-print-json-as-a-result-output
# You can run the application by clicking
# the 'Run App' button above.
#
@johndrummond
johndrummond / settingReactiveValTrigger
Created May 13, 2019 11:48
code showing that an observer that sets a reactive value, isn't invalidated by the reactive value being set elsewhere
#
#
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Reactive values updating"),
@johndrummond
johndrummond / shinyglobalpromise.R
Created May 9, 2019 09:13
long running task in shiny with task in global future
library(shiny)
library(DT)
library(dplyr)
library(future)
library(promises)
plan(multiprocess)
ui <- fluidPage(
verbatimTextOutput("timer"),
DTOutput("myTable")
@johndrummond
johndrummond / shinypromise.R
Created May 8, 2019 23:13
shiny app with long running calculation using promises
# notice the flush on the single user holds up the user updating, as the promise and reactive variable is there per user
library(shiny)
library(DT)
library(dplyr)
library(future)
library(promises)
plan(multiprocess)
ui <- fluidPage(
@johndrummond
johndrummond / shiny_invalidatelater_future.R
Created May 8, 2019 13:01
scheduled long running tasks in shiny with futures
library(shiny)
library(DT)
library(dplyr)
library(future)
library(magrittr)
plan(multiprocess)
dedupe <- function(r) {
makeReactiveBinding("val")
observe(val <<- r(), priority = 10)
@johndrummond
johndrummond / gist:0bbc846da698e0b7e84bff9d2871ae0b
Created May 2, 2019 12:03
compare observeEvent to observe plus isolate in a shiny app
# oberveEvent includes the ability of the first parameter to be an expression. But if the return value of that expression is
# null, the ignore null setting blocks updates, even though other parts of the expression are updating.
# in the example below with the default settings, button Event1 will only trigger the update of "observeEvent either button"
# after Event2 has been pushed at least once
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(