Skip to content

Instantly share code, notes, and snippets.

@ChrisBeeley
ChrisBeeley / app.R
Created March 12, 2021 16:58
Demo of reactive data and UI
library(palmerpenguins)
library(tidyverse)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Reactive example"),
sidebarLayout(
---
title: "Basic RMarkdown Shiny"
author: "Chris Beeley"
output: html_document
runtime: shiny
---
# Example RMarkdown document
This is an interactive document written in *markdown*. As you can see it is easy to include:
@ChrisBeeley
ChrisBeeley / server.R
Created December 22, 2015 22:30
Minimal example of a full Shiny application
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
@ChrisBeeley
ChrisBeeley / app.R
Created April 3, 2020 18:06
Test to see how app.R behaves the first time it runs and on subsequent runs
library(shiny)
library(tidyverse)
library(DT)
load("ae_attendances.RData")
Sys.sleep(10)
# filter to random 10 Trusts with a decent amount of data in
### Data load
library(tidyverse)
library(RMySQL)
library(readxl)
main <- read_excel("JISC_05-02-20.xlsx", skip = 1) %>%
rename(TeamC = `Team Number`, Date = CompletionDate) %>%
select(-starts_with("1."), -starts_with("2."), -starts_with("3."), -starts_with("4."))
https://github.com/HFAnalyticsLab
https://github.com/codonlibrary
https://github.com/royal-free-london
https://github.com/PublicHealthEngland
https://github.com/nhsuk
@ChrisBeeley
ChrisBeeley / server.R
Last active October 2, 2019 15:55
Demo to show widget types, return values and data types in Shiny
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")),
---
title: "Binomial confidence intervals"
author: "Chris Beeley"
date: "20/06/2019"
output: html_document
---
```{r setup, include=FALSE}
library(tidyverse)
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
})
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)) %>%