Skip to content

Instantly share code, notes, and snippets.

@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
@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
---
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 / 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: "Loop demo"
author: "Chris Beeley"
date: "21/04/2021"
output: html_document
params:
species: NA
---
```{r setup, include=FALSE}
# this is old code! I do not advocate doing any of the below :-)
rm(list=ls())
library(psych)
count.NAS=function(x) length(which(is.na(x)))
ASPECT=read.csv("ASPECT.csv")
HONOS=read.csv("HONOS.csv")
ESSENCES=read.csv("ESSENCES.csv")
library(tidyverse)
# produce data
pharmacy_sub <- pharmacy %>%
filter(Site1 == "Site C", NSVCode == "Drug A")
daily_data <- phaRmacyForecasting:::make_tsibble(pharmacy_sub, frequency = "Daily")
---
title: "Parameterised Reporting"
author: "Tina Simms"
date: "03/11/2021"
output: html_document
params:
month:
label: "Month of the Year"
value: January
input: select
@ChrisBeeley
ChrisBeeley / app.R
Created May 20, 2022 09:12
Test file saving on Shiny server
# Shiny app with 3 fields that the user can submit data for
ui <- fluidPage(
DT::dataTableOutput("responses", width = 300), tags$hr(),
textInput("name", "Name", ""),
checkboxInput("used_shiny", "I've built a Shiny app in R before", FALSE),
sliderInput("r_num_years", "Number of years using R",
0, 25, 2, ticks = FALSE),
actionButton("submit", "Submit")
)
library(sparkline)
library(formattable)
library(dplyr)
x = c(0, rep(1000, 5), rep(1000.000001, 5))
res <- mtcars |>
mutate(summary = as.character(
htmltools::as.tags(
sparkline(x, type = "bar",