Skip to content

Instantly share code, notes, and snippets.

View hypebright's full-sized avatar

Veerle van Leemput hypebright

View GitHub Profile
@hypebright
hypebright / shiny-destroy-observer.R
Created March 9, 2024 16:54
Demo demonstrating how to dynamically add and remove Shiny modules, and how to properly clean up modules once removed by using the destroy() method.
# Dynamic UI: demonstrate destroy() method on observer
# This example makes use of a module that dynamically creates pages
# Each server part of the module creates an observer that listens to an actionButton
# Whenever a page is removed, the observer is destroyed. The UI is removed with
# the nav_remove() function.
library(shiny)
library(bslib)
sportsPageUI <- function(id, page_name) {
@hypebright
hypebright / gargoyle_minimal_example.R
Created December 11, 2022 16:04
gargoyle example using init, trigger and watch
library(shiny)
library(gargoyle)
ui <- function(){
tagList(
actionButton("go", "Show me"),
h4('Output of pass_around$data'),
tableOutput("table")
)
}
@hypebright
hypebright / histoslider_demo.R
Created September 27, 2022 12:14
Demo of the histoslider package
# install histoslider
# remotes::install_github("cpsievert/histoslider")
# load libraries
library(shiny)
library(histoslider)
library(data.table)
library(quantmod) # to get current exchange rates
# load airbnb dataset containing properties in London
@hypebright
hypebright / reactable_demo.R
Last active May 18, 2022 14:38
Demo of the reactable package in Shiny using UK pharmaceutical data
# libraries
library(reactable) # version 0.2.3.9000
library(data.table)
library(shiny)
# Read in the data
# Data contains prescribing quantities for Aciclovir (limited range) and Pregabalin in February 2022
# in England, Scotland, Northern Ireland and Wales
# Made available under the Open Government License, retrieved from Pharmly Cloud Data by Analytic Health
@hypebright
hypebright / gt_demo.R
Created May 18, 2022 14:31
Demo of the gt table package using the Palmer Penguin dataset
# libraries
library(gt) # version 0.5.0
library(dplyr)
library(palmerpenguins)
# Create a gt table
penguins %>%
filter(sex == 'female') %>%
select(-year) %>%
We can't make this file beautiful and searchable because it's too large.
Primary Care Organisation;Brand;Company;Product;Dosage;Active Ingredients;BNF Chapter;BNF Section;BNF Sub Paragraph;Country;BNF Paragraph;Strength;Prescription Type;Units;Value
NHS Kent and Medway CCG;Generic;Generic;Pregabalin Capsule;Capsule;Pregabalin;Central Nervous System;Antiepileptic drugs;Control of epilepsy;England;Control of epilepsy;Pregabalin 50mg capsules;INN;230030;9694,96
NHS Kent and Medway CCG;Generic;Generic;Pregabalin Capsule;Capsule;Pregabalin;Central Nervous System;Antiepileptic drugs;Control of epilepsy;England;Control of epilepsy;Pregabalin 100mg capsules;INN;208665;10211,47
NHS North West London CCG;Generic;Generic;Pregabalin Capsule;Capsule;Pregabalin;Central Nervous System;Antiepileptic drugs;Control of epilepsy;England;Control of epilepsy;Pregabalin 75mg capsules;INN;203217;11322,05
@hypebright
hypebright / shiny_debounce_throttle_demo.R
Created March 27, 2022 09:10
Gist with an example demonstrating the usefulness of debouncing and throttling of a reactive expression in Shiny
library(shiny)
library(magrittr)
counts <-
reactiveValues(baseline = 0,
debounce = 0,
throttle = 0)
ui <- fluidPage(
titlePanel("Slowing down a chatty reactive expression 💬🦥 - demo"),
@hypebright
hypebright / shiny_localstorage_setdefaultinput.R
Created February 13, 2022 09:39
Simple example for demonstrating setting a default value for a picker based on local storage
library(shiny)
ui <- fluidPage(
shinyjs::useShinyjs(),
# event handler in JavaScript: handles requests from R
# tells JavaScript to call the function and to pass it a message that it got from R
tags$head(
tags$script("
library(shiny)
ui <- fluidPage(
shinyjs::useShinyjs(),
# event handler in JavaScript: handles requests from R
# tells JavaScript to call the function and to pass it a message that it got from R
tags$head(
tags$script("
@hypebright
hypebright / prophet_example.R
Created January 26, 2022 06:17
Very basic prophet example used in my presentation about Time Series Analysis in R
# Load libraries
library(prophet)
library(RCurl)
library(ggplot2)
# Get the data
url <-'https://raw.github.com/facebook/prophet/master/examples/example_retail_sales.csv'
df <- read.csv(url)