Skip to content

Instantly share code, notes, and snippets.

# Load libraries
library(tidyverse)
# Original names
df <- tibble(Q1=c(1), Q2=c(1), Q3=c(1), Q4=c(1), Q5=c(1), Q6=c(1), Q7=c(1), Q25_1=c(1), Q25_2=c(1), Q25_3=c(1), Q25_4=c(1), Q25_5=c(1), Q25_6=c(1), Q25_7=c(1), Q25_8=c(1), Q25_9=c(1), Q25_10=c(1), Q25_11=c(1), Q25_12=c(1), Q25_13=c(1), Q25_14=c(1), Q25_15=c(1), Q25_16=c(1), Q26_1=c(1), Q26_2=c(1), Q26_3=c(1), Q26_4=c(1), Q26_5=c(1), Q26_6=c(1), Q26_7=c(1))
df %>% glimpse()
# Option A) Using select and rename_with
df %>%
select(
@jrosell
jrosell / idescat-emex.R
Last active March 2, 2022 11:07
Obtenció de dades de "Municipi en xifres" de idescat via API en R.
library(tidyverse)
library(rvest)
library(xml2)
get_attrs <- function(df) {
ret <-
map(df, ~xml_attrs(df)) %>%
bind_rows %>%
rename(tipus = scheme)
ret
function t() {
var e;
s(this, t),
n(p((e = a.call(this))), "tileIndex", 0),
n(p(e), "rowIndex", 0),
n(p(e), "solution", void 0),
n(p(e), "boardState", void 0),
n(p(e), "evaluations", void 0),
n(p(e), "canInput", !0),
n(p(e), "gameStatus", Za),
library(RPostgres)
# Get and read the PDF
path <- file.path("os2.pdf")
pdf <- readBin(con = path, what = raw(), n = file.info(path)$size)
# Open it
browseURL(path)
# Connect to default DB and put seralized raw pdf in a data.frame
# Instead of a reactive chunk, have knitr convert a character vector "chunk" to HTML within a reactive context.
# Then feed that HTML to renderUI.
# Source: https://community.rstudio.com/t/feed-shiny-text-input-into-python-chunk/16098/3
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
library(shiny)
ui <- fluidPage(
titlePanel("Shiny updateInput"),
actionButton(
"input_update",
label = "Utilitzo updateInput",
icon = icon("arrow-up")
),
actionButton(
"click_button",
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
titlePanel("Shiny JavaScript"),
actionButton(
"javascript_update",
label = "Utilitzo javascript",
icon = icon("arrow-up")
),
library(shiny)
ui <- fluidPage(
titlePanel("Shiny Server"),
uiOutput("server_update"),
actionButton(
"click_button",
label = "Actualitza botó"
)
)
server <- function(input, output, session) {
library(shiny)
ui <- fluidPage(h1("Hola món"))
server <- function(input, output) {}
shinyApp(ui = ui, server = server)
library(tidyverse)
if(!require(timetk)) install.packages("timetk")
# Week number in x axis with daily data in y
timetk::bike_sharing_daily %>%
filter(dteday > '2012-11-01') %>%
ggplot(aes(dteday, windspeed)) +
geom_line() +
scale_x_date(
date_breaks = "1 week",