Skip to content

Instantly share code, notes, and snippets.

View hypebright's full-sized avatar

Veerle van Leemput hypebright

View GitHub Profile
@hypebright
hypebright / csv_reading_times.R
Last active July 11, 2022 04:36
Microbenchmark to compare reading times for a .csv file in R
library(microbenchmark)
library(data.table)
library(readr)
library(vroom)
library(iotools)
myfile <- 'mypath.csv'
microbenchmark(read.csv(myfile),
data.table::fread(myfile),
@hypebright
hypebright / shiny_callR_demo.R
Last active January 23, 2024 11:15
Small demo to use background processes in Shiny apps with callR
library(shiny)
library(callr)
ui <- fluidPage(
titlePanel('Using callR in Shiny'),
actionButton('start_job', 'Start Expensive Job'),
tableOutput('result_table')
)
@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)
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 / 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("
@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"),
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
Greater Glasgow and Clyde;Generic;Generic;Pregabalin Capsule;Capsule;Pregabalin;Central Nervous System;Antiepileptic drugs;Control of epilepsy;Scotland;Control of epilepsy;Pregabalin 300mg capsules;INN;1
@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) %>%
@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 / 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