Skip to content

Instantly share code, notes, and snippets.

View JohnCoene's full-sized avatar
🍰
Cake!

John Coene JohnCoene

🍰
Cake!
View GitHub Profile
@JohnCoene
JohnCoene / shinydash-waiter.R
Last active May 21, 2020 11:29
shinydashboard overlay waiter on tab content
## app.R ##
library(shiny)
library(waiter)
library(shinydashboard)
# add JavaScript to add an id to the <section> tag so we can overlay waiter on top of it
add_id_to_section <- "
$( document ).ready(function() {
var section = document.getElementsByClassName('content');
section[0].setAttribute('id', 'waiter-content');
library(shiny)
library(waiter)
ui <- navbarPage(
"example",
id = "tabs",
header = list(
use_waiter()
),
tabPanel(
@JohnCoene
JohnCoene / brazil.R
Last active May 10, 2020 19:07
Brazil geojson with R
library(echarts4r)
library(sp)
library(raster)
library(geojsonio)
# get the shapefile
brazil_sp <- raster::getData('GADM', country = 'BRAZIL', level = 3)
# simplify
brazil_small <- rmapshaper::ms_simplify(brazil_sp, keep = 0.05)
@JohnCoene
JohnCoene / sigmajs-example.R
Created May 3, 2020 10:29
Sigmajs examples
nodes <- sg_make_nodes()
edges <- sg_make_edges(nodes, 17)
# Save image
sigmajs() %>%
sg_nodes(nodes, id, size) %>%
sg_edges(edges, id, source, target) %>%
sg_export_img() %>% # bind to button
sg_button("export_img", "download") # click button to obtain png
@JohnCoene
JohnCoene / cicerone-opacity.R
Last active March 31, 2020 13:14
Opacity with {cicerone}
library(shiny)
library(cicerone)
guide <- Cicerone$
new(animate = F)$
step(
el = "text_inputId",
title = "Text Input",
description = "This is where you enter the text you want to print."
)$
@JohnCoene
JohnCoene / echarts4r_grid.R
Last active February 11, 2020 12:47
Padding Axis
library(echarts4r)
# e_grid also accepts percentages
# e.g.: e_grid(left = "5%")
# useful for better responsiveness (mobile/desktop)
mtcars %>%
tibble::rownames_to_column() %>%
e_charts(rowname) %>%
e_line(qsec) %>%
@JohnCoene
JohnCoene / vscode.json
Created January 24, 2020 08:30
Key bindngs
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+shift+m",
"command": "editor.action.insertSnippet",
"args": {
"snippet": " %>% "
}
},
{
#' Compile an R file into a JS file
#' @param input A character string; the input file.
#' @param output A character string; the output file. When the
#' output is "", the result is printed to the standard output.
#' @export
compile_r <- function(input) {
input <- rlang::enexpr(input)
parse(text = deparse(input)) %>%
purrr::map(rewrite) %>%
purrr::map(deparse_js) %>%
@JohnCoene
JohnCoene / app.R
Last active January 7, 2020 15:47
Password Shiny
library(shiny)
# remotes::install_github("JohnCoene/nter")
addResourcePath(
'www', 'assets'
)
login_form <- modalDialog(
fluidRow(
column(9, passwordInput("password", "Password", width = "100%")),
@JohnCoene
JohnCoene / wordcloud-echarts4r.R
Last active December 19, 2019 11:57
Wordcloud with line break and echarts4r
library(echarts4r)
# frequencies
tf <- tibble::tibble(
phrases = c("anomaly trip", "a sentence", "some phrase", "another sentence"),
frequency = c(10, 20, 30)
)
# add line break
tf$phrases <- gsub(" ", "\n", tf$phrases)