Skip to content

Instantly share code, notes, and snippets.

@jrosell
jrosell / zoho-analytics-crawl-live.R
Created August 26, 2024 16:33
It can login and it can see the first rows, but it can't scroll down.
library(tidyverse)
library(rvest)
sess <- read_html_live("https://analytics.zoho.com/open-view/your-zoho-table")
sess$view()
try({
sess$type("#passwordValue", "yourpassword")
sess$click("#submitButton")
})
# NOTE: It's not working on Posistron because of rJava, it works on RStudio.
if(!"rlang" %in% installed.packages()){
if(!interactive()) { stop("The package \"rlang\" is required.") }
cat("The package \"rlang\" is required.\n✖ Would you like to install it?\n\n1: Yes\n2: No\n\nSelection:")
if (readLines(n = 1) == "1"){
install.packages("rlang")
}
}
rlang::check_installed(
if(!"rlang" %in% installed.packages()){
if(!interactive()) { stop("The package \"rlang\" is required.") }
cat("The package \"rlang\" is required.\n✖ Would you like to install it?\n\n1: Yes\n2: No\n\nSelection:")
if (readLines(n = 1) == "1"){
install.packages("rlang")
}
}
rlang::check_installed(
"jrrosell (>= 0.0.0.9006)",
action = \(pkg,...) {
debug <- FALSE
#' @noRd
preparations <- \() {
cat(glue::glue("preparations")); cat("\n")
if(!"rlang" %in% installed.packages()){
if(!interactive()) { stop("The package \"rlang\" is required.") }
cat("The package \"rlang\" is required.\n✖ Would you like to install it?\n\n1: Yes\n2: No\n\nSelection:")
if (readLines(n = 1) == "1"){
install.packages("rlang")
@jrosell
jrosell / grammar-of-music.R
Created July 10, 2024 08:10
Head, shoulders, knees and toes...
# Ubuntu/debian: sudo apt-get install musescore
# pak::pak("flujoo/gm")
Sys.setenv(MUSESCORE_PATH = "/usr/bin/musescore")
library(gm)
(Music() +
Meter(4, 4) +
Line(
pitches = c(
c("G4", "A4", "G4", "F#4"),
---
title: "robo violencia"
output: html_document
date: "2024-06-19"
editor_options:
chunk_output_type: console
---
## CCAA
get_mode <- \(x) {
r <- table(x)
names(r[r == max(r)])
}
# For example:
# > get_mode(c(1,2,2,3,3,4))
# 2 3
#!/usr/bin/env Rscript
cat("==========================================================================\n")
cat("Example of strategy patern in R: Multiple ways to show routes. \n")
# Problem:
# You build a navigation app for casual travelers and help users quickly orient themselves in any city.
#
# - The first only build the routes over roads.
# - Next update, you added an option to build walking routes.
@jrosell
jrosell / shiny-javascript-communication.R
Last active April 5, 2024 12:44
Update value in a hidden field from R or from JavaScript using the Shiny package.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
hidden(
textInput("my_input", label = "my_input", value = "Initial value")
),
textOutput("my_output"),
actionButton("my_js_button","Update from JavaScript"),