Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Beeley ChrisBeeley

View GitHub Profile
@ChrisBeeley
ChrisBeeley / server.R
Last active Aug 29, 2015
Minimal application for Shiny Book, 2nd edition
View server.R
library(shiny) # load Shiny at the top of both scripts
shinyServer(function(input, output) { # define application in here
output$textDisplay <- renderText({ # mark function as reactive
# and assign to output$textDisplay for passing to ui.R
paste0("You said '", input$comment, # from the text
"'. There are ", nchar(input$comment), # input control as
" characters in this.") # defined in ui.R
View server.R
####################################
##### minimal example - server.R ###
####################################
library(shiny) # load shiny at beginning at both scripts
shinyServer(function(input, output) { # server is defined within these parentheses
output$textDisplay <- renderText({ # mark function as reactive and assign to
# output$textDisplay for passing to ui.R
@ChrisBeeley
ChrisBeeley / dropdownDepend.js
Created Jan 1, 2016
Sending messages to and from client and server using JavaScript/ Shiny
View dropdownDepend.js
<script type="text/javascript">
// Shiny function to receive messages
Shiny.addCustomMessageHandler("sendMessage",
function(message) {
// call this before modifying the DOM
Shiny.unbindAll();
/* delete the dropdown if it already
@ChrisBeeley
ChrisBeeley / app.R
Last active Jun 12, 2017
Single file app which takes various GET parameters and returns the appropriate date boxes (see below for link to blog post)
View app.R
library(shiny)
library(lubridate)
server = function(input, output, session){
# type = date rolling n months, quarters
output$dateControls <- renderUI({
View dplyrReprex
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 3.4.4
#> -- Attaching packages ----------------------------------------------------------------------------------------------- tidyverse 1.2.1 --
#> v ggplot2 3.0.0 v purrr 0.2.4
#> v tibble 1.4.2 v dplyr 0.7.6
#> v tidyr 0.8.1 v stringr 1.3.0
#> v readr 1.1.1 v forcats 0.3.0
#> Warning: package 'ggplot2' was built under R version 3.4.4
#> Warning: package 'tibble' was built under R version 3.4.4
#> Warning: package 'readr' was built under R version 3.4.4
View big_pipe.R
fixedData[, missnum > 2] %>%
gather(L1, value) %>%
filter(!is.na(value)) %>%
left_join(select(questionFrame, code, value), by = c("L1" = "code")) %>%
select(-L1) %>%
group_by(value.y) %>%
count(value.x) %>%
mutate(prop = prop.table(n) * 100) %>%
select(-n) %>%
mutate(value.x = factor(value.x, levels = 1:5)) %>%
View server.R
function(input, output) { # define application in here
output$textDisplay <- renderText({ # mark function as reactive
# and assign to output$textDisplay for passing to ui.R
paste0("You said '", input$comment, # from the text
"'. There are ", nchar(input$comment), # input control as
" characters in this.") # defined in ui.R
})
View binom_conf.Rmd
---
title: "Binomial confidence intervals"
author: "Chris Beeley"
date: "20/06/2019"
output: html_document
---
```{r setup, include=FALSE}
library(tidyverse)
@ChrisBeeley
ChrisBeeley / server.R
Last active Oct 2, 2019
Demo to show widget types, return values and data types in Shiny
View server.R
function(input, output) {
output$textDisplay <- renderTable({
getMat = matrix(
c(paste(input$checkGroup, collapse=','), class(input$checkGroup),
input$boxInput, class(input$boxInput),
as.character(as.Date(input$theDate, origin = "1970-01-01")), class(input$theDate),
paste(as.character(as.Date(input$dateRange[[1]], origin = "1970-01-01")),
as.character(as.Date(input$dateRange[[2]], origin = "1970-01-01")),
View List of NHS relevant GitHubs
https://github.com/HFAnalyticsLab
https://github.com/codonlibrary
https://github.com/royal-free-london
https://github.com/PublicHealthEngland
https://github.com/nhsuk