Commit e2e9f203 authored by numeroteca's avatar numeroteca
Browse files

make app search available

parent 5ca13c42
......@@ -6,14 +6,14 @@ library(plotly)
# setttings: captions
subtitle_text <- "Telediarios de TVE. "
caption_text <- "Datos: verba.civio.es (Civio). Gráfico: numeroteca.org"
today <- Sys.Date()
# Define UI ----
ui <- fluidPage(
tags$head(
# Note the wrapping of the string in HTML()
tags$style(HTML("
@import url('https://fonts.googleapis.com/css2?family=Robot+COndensed&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Robot+Condensed&display=swap');
body {
background-color: #fafafa;
font-family: 'Roboto Condensed', sans-serif;
......@@ -42,13 +42,19 @@ ui <- fluidPage(
# Input search
textInput("search",
label="Búsqueda",
# value="cifuentes"
value="coronavirus"
),
p("escribe una palabra y Aplica filtros"),
actionButton("go", "Aplica filtros",style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),
hr(),
dateInput("dateinit", "Fecha inicio", value = "2013-12-26" ),
dateInput("datefinish", "Fecha final", value = today ),
# dateInput("dateinit", "Fecha inicio", value = "2018-03-01" ),
# dateInput("datefinish", "Fecha final", value = "2018-05-01" ),
hr(),
# TODO set limits to chart
dateInput("date1", "Fecha transcripción", value = "2018-04-04" ),
dateInput("date1", "Fecha transcripción", value = "2020-04-03" ),
# dateInput("date2", "Date ends", value = "2012-02-29"),
# # select period limits
......@@ -70,12 +76,12 @@ ui <- fluidPage(
sliderInput(inputId = "heading",
label = "Cabecera (segundos)",
min = 60, max = 360, value = 120
min = 60, max = 360, value = 180
),
sliderInput(inputId = "datebreaks",
label = "nº Particiones",
min = 1, max = 365, value = 1
min = 1, max = 31, value = 1
),
selectInput(inputId = "breaks",
label = "Particiones",
......@@ -218,7 +224,14 @@ server <- function(input, output) {
date1 <- reactive({
input$date1
})
# time limits
dateinit <- eventReactive(input$go, {
input$dateinit
})
datefinish <- eventReactive(input$go, {
input$datefinish
})
# select date for transcripts
lineas <- eventReactive(input$go, {
input$lineas
......@@ -273,17 +286,26 @@ server <- function(input, output) {
# Plot Cuándo -------
output$whenPlot <- renderPlot({
print( paste("max", max( mydata()$date)) )
print( paste("min", min( mydata()$date)) )
the_plot <- mydata() %>%
# elimina los que está npor encima de 70min
filter ( ! ( start_time/60 > 61 ) ) %>%
ggplot() + #%>% filter( date> "2018-04-01" & date < "2018-04-05" )
# primer minuto y medio (90 segundos)
geom_rect(aes( xmin=min(mydata()$date2+ 41000) , xmax=max(mydata()$date2+ 82800+ 40000), ymin=0,
ymax= heading()/60), alpha = 0.02, fill = "lightgrey" ) +
geom_rect( aes(
# xmin=min((mydata()$date) , xmax=max( mydata()$date),
xmin= dateinit() , xmax= datefinish(),
ymin=0, ymax= heading()/60 ), alpha = 0.2, fill = "lightgrey" ) +
# geom_rect(aes( xmin=min(data$date), xmax=max(data$date),
# ymin=0,ymax=240/60), alpha = 0.2, fill = "lightgrey"
# ) +
# Text indicating heading time
# geom_text( data = mydata() %>% top_n(1,date), aes (min(mydata()$date2+500000), 2, label="primeros 90 segundos"),base_family = "Roboto Condensed") +
geom_segment( aes(x = date2 + 82800, xend = date2 + 82800,
geom_segment( aes(x = date, xend = date,
y = start_time/60, yend = (start_time+30)/60),
alpha = 0.8,
# size=4
......@@ -291,7 +313,7 @@ server <- function(input, output) {
) + #, color=caso
# selected date
geom_segment( data = mydata() %>% filter( date == date1() ),
aes(x = date2 + 82800, xend = date2 + 82800,
aes(x = date, xend = date,
y = start_time/60, yend = (start_time+30)/60),
alpha = 0.8,
color = "#cc001f",
......@@ -300,19 +322,24 @@ server <- function(input, output) {
# geom_point( aes(x = date2, y = start_time/60), alpha = 0.8, size=2) + #, color=caso
geom_hline(aes(yintercept=0), size=0.1) +
theme_minimal(base_family = "Roboto Condensed", base_size = 18) +
scale_x_datetime(date_breaks = paste(datebreaks(),breaks()),
scale_x_date(date_breaks = paste(datebreaks(),breaks()),
date_labels = label(),
# date_labels = "%d",
expand= c(0.01,0.05),
#secondary axis to add months
sec.axis = sec_axis(~ .,
labels = scales::time_format("%b/%y"))) +
limits = c(as.Date( dateinit() ), as.Date( datefinish() ) ),
# limits = c( as.Date("2014-03-03" ), as.Date("2021-03-03") )
# limits = c( as.Date("2018-03-01" ), as.Date("2018-05-01") )
# limits = c( as.Date("2020-01-01" ), as.Date("2021-01-01") )
sec.axis = sec_axis(~ .)
# labels = scales::time_format("%b/%y"))
) +
labs(title = paste0("Cuándo hablan de '",search_word(), "' en los telediarios"),
subtitle = paste0(subtitle_text,
"Periodo: ",
substr( min(mydata()$date2),1,10),
substr( min(mydata()$date),1,10),
" - ",
substr( max(mydata()$date2),1,10),
substr( max(mydata()$date),1,10),
"."
),
x = "",
......@@ -339,13 +366,17 @@ server <- function(input, output) {
filter ( ! ( start_time/60 > 61 ) ) %>%
ggplot() + #%>% filter( date> "2018-04-01" & date < "2018-04-05" )
# primer minuto y medio (90 segundos)
geom_rect(aes( xmin=min(mydata()$date2+ 41000) , xmax=max(mydata()$date2+ 82800+ 40000), ymin=0,
ymax= heading()/60), alpha = 0.02, fill = "lightgrey" ) +
geom_rect( aes(
# xmin=min((mydata()$date) , xmax=max( mydata()$date),
xmin= dateinit() , xmax= datefinish(),
ymin=0, ymax= heading()/60 ), alpha = 0.4, fill = "lightgrey" ) +
# geom_rect(aes( xmin=min(mydata()$date) , xmax=max(mydata()$date), ymin=0,
# ymax= heading()/60), alpha = 0.02, fill = "lightgrey" ) +
# Text indicating heading time
# geom_text( data = mydata() %>% top_n(1,date), aes (min(mydata()$date2+500000), 2, label="primeros 90 segundos"),base_family = "Roboto Condensed") +
geom_segment( aes(x = date2 + 82800, xend = date2 + 82800,
geom_segment( aes(x = date, xend = date,
y = start_time/60, yend = (start_time+30)/60,
text = paste0("", content, " <br>", date, "<br>", round(start_time/60, digits = 1 ), "")
text = paste0("", content, " <br>", date, "<br>", round(start_time/60, digits = 1 ), " min")
),
alpha = 0.8,
# size=4
......@@ -361,19 +392,21 @@ server <- function(input, output) {
# ) + #, color=caso
geom_hline(aes(yintercept=0), size=0.1) +
theme_minimal(base_family = "Roboto Condensed", base_size = 18) +
scale_x_datetime(date_breaks = paste(datebreaks(),breaks()),
scale_x_date(date_breaks = paste(datebreaks(),breaks()),
limits = c(as.Date( dateinit() ), as.Date( datefinish() ) ),
date_labels = label(),
# date_labels = "%d",
expand= c(0.01,0.05),
#secondary axis to add months
sec.axis = sec_axis(~ .,
labels = scales::time_format("%b/%y"))) +
# sec.axis = sec_axis(~ .,
# labels = scales::time_format("%b/%y"))
) +
labs(title = paste0("Cuándo hablan de '",search_word(), "' en los telediarios"),
subtitle = paste0(subtitle_text,
"Periodo: ",
substr( min(mydata()$date2),1,10),
substr( min(mydata()$date),1,10),
" - ",
substr( max(mydata()$date2),1,10),
substr( max(mydata()$date),1,10),
"."
),
x = "",
......@@ -395,16 +428,15 @@ server <- function(input, output) {
'<sup>',
subtitle_text,
'Periodo: ',
substr( min(mydata()$date2),1,10),
substr( min(mydata()$date),1,10),
' - ',
substr( max(mydata()$date2),1,10),
substr( max(mydata()$date),1,10),
'.','</sup>'))
, annotations =
list(x = 1, y = -0.11, text = "Gráfico: numeroteca (<a style='color:grey;' href='https://montera34.com'>montera34.com</a>).
Datos: RTVE a través de <a style='color:grey;'href='https://verba.civio.es (Civio)'>verba.civio.es (Civio)</a>",
list(x = 1, y = -0.11, text = "Gráfico: numeroteca (<a style='color:grey;' href='https://montera34.com'>montera34.com</a>). Datos: RTVE a través de <a style='color:grey;'href='https://verba.civio.es (Civio)'>verba.civio.es (Civio)</a>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=-38,
font=list(size=15, color="grey")
xanchor='right', yanchor='auto', xshift=0, yshift=-24,
font=list(size=14, color="grey")
),
legend = list(font = list(size = 10))
)
......@@ -421,35 +453,36 @@ server <- function(input, output) {
filter ( ! ( start_time/60 > 70 ) ) %>%
ggplot( ) +
# bars
geom_bar(aes( x=date2), fill = "#555555") + # si hay clasificación por caso: fill=caso
geom_bar(aes( x=date), fill = "#555555") + # si hay clasificación por caso: fill=caso
# selected date
# tengo que hacerlo así porque no me deja seleccionar solamente una fecha TODO: investigar por qué
geom_bar( data = mydata() %>% filter( date > date1() - 1 & date < date1() + 2 ), # %>% filter( date == date1() )
aes(x=date2),
aes(x=date),
# width = 1,
fill = "#cc001f"
) +
# selected date
geom_bar( data = mydata() %>% filter( date > date1() - 0 & date < date1() + 3 ), # %>% filter( date == date1() )
aes(x=date2),
aes(x=date),
# width = 1,
fill = "#555555"
) +
theme_minimal(base_family = "Roboto Condensed", base_size = 22) +
# scale_x_datetime(date_breaks = "1 day", date_labels = "%d") +
scale_x_datetime(date_breaks = paste(datebreaks(),breaks()),
scale_x_date(date_breaks = paste(datebreaks(),breaks()),
limits = c(as.Date( dateinit() ), as.Date( datefinish() ) ),
date_labels = label(),
expand= c(0.00,0.00),
expand= c(0,0),
#secondary axis to add months
sec.axis = sec_axis(~ .,
labels = scales::time_format("%b/%y"))
# sec.axis = sec_axis(~ .,
# labels = scales::time_format("%b/%y"))
) +
labs(title = paste0("Cuánto hablan de '",search_word(), "' en los telediarios"),
subtitle = paste0(subtitle_text,
"Periodo: ",
substr( min(mydata()$date2),1,10),
substr( min(mydata()$date),1,10),
" - ",
substr( max(mydata()$date2),1,10),
substr( max(mydata()$date),1,10),
"."
),
x = "",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment