Commit 5ca13c42 authored by numeroteca's avatar numeroteca
Browse files

add interactive poltly chart to app

parent bbb3e214
......@@ -39,13 +39,14 @@ ui <- fluidPage(
# Sidebar panel for inputs ----
sidebarPanel(
actionButton("go", "Aplica filtros",style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),
# Input search
textInput("search",
label="Búsqueda:",
label="Búsqueda",
value="coronavirus"
),
p("escribe una palabra y Aplica filtros"),
actionButton("go", "Aplica filtros",style="color: #fff; background-color: #337ab7; border-color: #2e6da4"),
hr(),
# TODO set limits to chart
dateInput("date1", "Fecha transcripción", value = "2018-04-04" ),
# dateInput("date2", "Date ends", value = "2012-02-29"),
......@@ -128,6 +129,9 @@ ui <- fluidPage(
# we don't change its position
# div(
# style = "position:relative",
plotlyOutput("whenPlotInteractive", height = 500),
hr(),
# h5("Gráficos para descargar"),
plotOutput("whenPlot", height = 500),
tableOutput("quotes"),
plotOutput("barPlot", height = 500),
......@@ -267,10 +271,10 @@ server <- function(input, output) {
# })
# Plot Cuándo
# Plot Cuándo -------
output$whenPlot <- renderPlot({
mydata() %>%
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" )
......@@ -303,7 +307,7 @@ server <- function(input, output) {
#secondary axis to add months
sec.axis = sec_axis(~ .,
labels = scales::time_format("%b/%y"))) +
labs(title = paste0("Cuándo hablan de ´",search_word(), "´ en los telediarios"),
labs(title = paste0("Cuándo hablan de '",search_word(), "' en los telediarios"),
subtitle = paste0(subtitle_text,
"Periodo: ",
substr( min(mydata()$date2),1,10),
......@@ -311,7 +315,7 @@ server <- function(input, output) {
substr( max(mydata()$date2),1,10),
"."
),
x = "fecha",
x = "",
y = "minutos desde el inicio",
caption = caption_text) +
theme(
......@@ -324,9 +328,91 @@ server <- function(input, output) {
) +
facet_wrap( ~telediario, ncol=1)
the_plot
})
# Plotly Cuándo --------
output$whenPlotInteractive <- renderPlotly({
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" ) +
# 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,
y = start_time/60, yend = (start_time+30)/60,
text = paste0("", content, " <br>", date, "<br>", round(start_time/60, digits = 1 ), "")
),
alpha = 0.8,
# size=4
size= lineas()
) + #, color=caso
# selected date
# geom_segment( data = mydata() %>% filter( date == date1() ),
# aes(x = date2 + 82800, xend = date2 + 82800,
# y = start_time/60, yend = (start_time+30)/60),
# alpha = 0.8,
# color = "#cc001f",
# size= lineas()
# ) + #, 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()),
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"))) +
labs(title = paste0("Cuándo hablan de '",search_word(), "' en los telediarios"),
subtitle = paste0(subtitle_text,
"Periodo: ",
substr( min(mydata()$date2),1,10),
" - ",
substr( max(mydata()$date2),1,10),
"."
),
x = "",
y = "minutos desde el inicio",
caption = caption_text) +
theme(
panel.grid.minor.x = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.major.y = element_blank(),
axis.ticks = element_line(color = "#777777"),
axis.text.x = element_text(size = xlabelsize() )
) +
facet_wrap( ~telediario, ncol=1)
p <- ggplotly( the_plot, tooltip = "text") %>%
layout(title = list(text = paste0('Cuándo hablan de "',search_word(), '" en los telediarios',
'<br>',
'<sup>',
subtitle_text,
'Periodo: ',
substr( min(mydata()$date2),1,10),
' - ',
substr( max(mydata()$date2),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>",
showarrow = F, xref='paper', yref='paper',
xanchor='right', yanchor='auto', xshift=0, yshift=-38,
font=list(size=15, color="grey")
),
legend = list(font = list(size = 10))
)
p
})
# Plot columns ------------
output$barPlot <- renderPlot({
......@@ -358,7 +444,7 @@ server <- function(input, output) {
sec.axis = sec_axis(~ .,
labels = scales::time_format("%b/%y"))
) +
labs(title = paste0("Cuánto hablan de ´",search_word(), "´ en los telediarios"),
labs(title = paste0("Cuánto hablan de '",search_word(), "' en los telediarios"),
subtitle = paste0(subtitle_text,
"Periodo: ",
substr( min(mydata()$date2),1,10),
......@@ -366,7 +452,7 @@ server <- function(input, output) {
substr( max(mydata()$date2),1,10),
"."
),
x = "fecha",
x = "",
y = "nº de frases",
caption = caption_text) +
theme(
......
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