Skip to content

Instantly share code, notes, and snippets.

View aarong1's full-sized avatar
🌴
On vacation

Aaron Gorman aarong1

🌴
On vacation
View GitHub Profile
@aarong1
aarong1 / dockerfile
Last active October 9, 2021 20:52
Boilerplate Rshiny dockerfile. The dependencies are created and stored in the .renv file. This is done by calling renv::init() and renv::snapshot() #renv #shiny-server #r #docker. NB 'storage_app in lines 24 and 26 need changes to your application name. Run from app directory.
# Base image https://hub.docker.com/u/rocker/
FROM rocker/shiny:latest
# system libraries of general use
## install debian packages
RUN apt-get update -qq && apt-get -y --no-install-recommends install \
libxml2-dev \
libcairo2-dev \
libsqlite3-dev \
libmariadbd-dev \
@aarong1
aarong1 / reactable_selected_row_color_app.R
Last active October 9, 2021 20:18
This is a solution that gets rid of the dot that is default were using selected rows in reactable. This code snippet demonstrates a coloured row like that of DataTables for selected elements that gets rid of the dot but runs a bit slower. Thanks #r #shiny #reactable
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
@aarong1
aarong1 / reacttable_formatting.R
Created October 25, 2021 13:17
How to quickly format a reacttable output in R
reactable(head(testType,4),
defaultColDef = colDef(
align = "center",
minWidth = 50,
headerStyle = list(background = "#f7f7f8")),
columns=list(Created=colDef(minWidth=80))
@aarong1
aarong1 / inline_css.R
Last active October 25, 2021 15:59
common inline css styling options for R and Rshiny
p(style=
'font-size:10px;
font-weight;bold;
color:white; #font color isconfusingy called color
text-align:center
'
)
#borders
@aarong1
aarong1 / display_inline_block.R
Created October 25, 2021 16:09
display inline block css
span(style="display: inline-block;vertical-align:top; width: 350px;",
sliderInput(inputId = 'selectDate',
ticks = TRUE,
dragRange = TRUE,
label = 'Select Date',
min = min(casePC$DoR,na.rm=T),
max = max(casePC$DoR,na.rm=T),
animate = TRUE,width='500',
value = c(Sys.Date()-100, max(casePC$DoR,na.rm=T)-1))),
span(style="display: inline-block;vertical-align:top; width: 350px;",
nodes_tot%>%
slice_head(n = 50)%>%
unite(FirstName,LastName,col='FullName')%>%
group_by(Latitude,Longitude)%>%
mutate(label=c(FullName))%>%
#mutate(label1=list(FullName))%>%
mutate(label2=paste(as.vector(label),sep=' ',collapse= '<br>' ))%>%
# mutate(label3=paste(label,sep=' ',collapse= ''))%>%
# mutate(label4=paste(as.vector(label1),sep=' ',collapse= ''))%>%
# mutate(label5=paste(label1,sep=' ',collapse= ''))%>%
@aarong1
aarong1 / characterise vector.R
Created October 25, 2021 18:05
characterise nested df for pretty printing
Cclusters1 <- Cclusters%>%
distinct(CaseNumber,ClusterID)%>%
group_by(CaseNumber)%>%
mutate(wot=all(is.na(ClusterID)))%>%
group_by(CaseNumber)%>%
summarise(ls=list(ClusterID),wot)%>%
mutate(clusters=paste0(ls))%>%
mutate(clusters=str_replace_all(clusters,pattern = '\\(',replacement=''))%>%
mutate(clusters=str_replace_all(clusters,pattern = '\\)',replacement=''))%>%
@aarong1
aarong1 / spatial_lines.R
Created October 25, 2021 18:45
display the graph transmission network as a geospatial figure.
leaflet(geo_lines)%>%
addTiles()%>%
addPolylines(stroke = 'blue',color = 'black',
weight = 1,opacity = 1,fill = 'green',
fillOpacity = 1,dashArray = 17)
nodes_sub <- igraph::as_data_frame(graph_tot_sub,what='vertices')
ed <- igraph::as_data_frame(graph_tot_sub,what='edges')
@aarong1
aarong1 / leaflet_R
Created October 25, 2021 18:47
boilerplate leaflet map in R
lgd_shape1$values <- plot$sum_pos[m]
#MAP-----
labels <- sprintf(
"<strong>%s</strong>:<br/>: %g ",
lgd_shape1$LGDNAME, plot$sum_pos[m]) %>%
lapply(htmltools::HTML)
#pal1 <- colorFactor("YlOrRd", domain = lgd_shape1$WARNING)
@aarong1
aarong1 / sparkline_renderer.R
Created November 23, 2021 18:50
code snippet so that all sparklines can be displayed on all pages of a DT
code snippet to get sparklines to render on all pages of a datable
options = list(
fnDrawCallback = htmlwidgets::JS(
'
function(){options = list(
fnDrawCallback = htmlwidgets::JS(
function(){
HTMLWidgets.staticRender();
}