This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| ui <- function(request){ | |
| tagList( | |
| tags$script( | |
| "$(function(){ | |
| $(this).bind('contextmenu', function (e) { | |
| e.preventDefault() | |
| Shiny.setInputValue('plop', Math.random()); | |
| }); | |
| });" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %>% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(patchwork) | |
| library(ggplot2) | |
| library(purrr) | |
| library(dplyr) | |
| library(glue) | |
| map( | |
| 5:8, | |
| ~iris %>% | |
| filter(Petal.Length < .x) %>% | |
| ggplot() + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="post"> | |
| <h2>{{ title }} </h2> | |
| {{content}} | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| snippet module | |
| ${1:name}UI <- function(id){ | |
| ns <- NS(id) | |
| tagList( | |
| ) | |
| } | |
| ${1:name} <- function(input, output, session){ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Make a function sleep | |
| sleepy <- function(fun, sleep){ | |
| function(...){ | |
| Sys.sleep(sleep) | |
| fun(...) | |
| } | |
| } | |
| sleep_print <- sleepy(print, 2) |