---
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
pacman::p_load(
tidyverse,
gtrendsR,
sf,
leaflet
)
```
# Tendencias de México
```{r eruptions, echo=FALSE}
statesJSON <- st_read("mx-states.geo.json")
```
```{r}
inputPanel(
textInput(
inputId="keyword",
label="Término de búsqueda:",
value="Google I/O",
placeholder="Bitcoin"
)
)
```
```{r states}
colors <- colorNumeric("RdYlBu",domain=states$hits)
renderLeaflet({
# 23.6345° N, 102.5528° W
leaflet(states) %>%
addTiles() %>%
setView(lat=23.6345,lng=-102.5528,zoom=4) %>%
addPolygons(
weight=1,
color="#232323",
opacity=0.8,
fillOpacity=0.8,
fillColor=colors(states$hits)
)
})
```
```{r statesJSON}
renderTable({
trends <- gtrends(
keyword=input$keyword,
geo="MX",
tz="America/Mexico_City",
time="now 7-d"
)
trends <- trends$interest_by_region
trends$name <- trends$location
trends <- trends %>%
mutate(
name=case_when(
name=="State of Mexico" ~ "Estado De Mexico",
name=="Mexico City" ~ "Ciudad De Mexico",
!is.na(name) ~ name
)
)
states <- statesJSON %>% left_join(trends,by="name")
trends %>% select(-name)
})
```
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎