Skip to content

Instantly share code, notes, and snippets.

View ColinFay's full-sized avatar
🦷
Because why not

Colin Fay ColinFay

🦷
Because why not
View GitHub Profile
<div class="post">
<h2>{{ title }} </h2>
{{content}}
</div>
library(patchwork)
library(ggplot2)
library(purrr)
library(dplyr)
library(glue)
map(
5:8,
~iris %>%
filter(Petal.Length < .x) %>%
ggplot() +
@ColinFay
ColinFay / geoloc.R
Last active August 6, 2018 22:04
geoloc shiny
library(shiny)
library(leaflet)
ui <- fluidPage(
h2("Where Am I?"),
tags$p("Click the button to get your coordinates"),
tags$button(onclick = "getLocation()", "Try it"),
tags$p(id = "where"),
leafletOutput("lf"),
@ColinFay
ColinFay / df_to_dygraph.R
Last active November 8, 2018 09:13
df to dygraph?
library(dygraphs)
library(magrittr)
df <- data.frame(
hour = seq( as.POSIXct("2019-01-01"), as.POSIXct("2019-01-02"), length.out = 48 ),
num = 1:48,
freq = rep(1:2, times = 24)
)
# Doesn't work
df %>%
download.file("https://images1.westword.com/imager/u/745xauto/9813472/mg_3662.jpg", "img.jpg")
img <- jpeg::readJPEG("img.jpg")
library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
annotation_custom(rasterGrob(img,
width = unit(1,"npc"),
height = unit(1,"npc"))) +
geom_point()
unlink("img.jpg")
library(shiny)
# You can put input to both your functions
mod_ui <- function(id, title){
# The ns here is a function that will help to 'namespace' the ids
# In other words, it will turn "go" into "chosennamespace-go"
ns <- NS(id)
tagList(
h2(title),
selectInput(
@ColinFay
ColinFay / shiny-right-click.R
Created July 18, 2019 11:53
Demo of event from right click in shiny
library(shiny)
ui <- function(request){
tagList(
tags$script(
"$(function(){
$(this).bind('contextmenu', function (e) {
e.preventDefault()
Shiny.setInputValue('plop', Math.random());
});
});"
---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, Inc."
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
@ColinFay
ColinFay / r-from-source.md
Created November 13, 2019 09:49
Installing R from source

Install R from source

Set R version and dl it

(you can modify the cran mirror)

R_VERSION='3.6.1'
wget https://cran.univ-paris1.fr/src/base/R-3/R-${R_VERSION}.tar.gz
@ColinFay
ColinFay / browser_n()
Created November 26, 2019 20:52
browser_n
browser_n <- function(n){
i <- 0
function(...){
i <<- i + 1
if (n >= i){
browser(...)
} else {
invisible(NULL)
}
}