forked from JohnCoene/coronavirus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_news.R
72 lines (64 loc) · 1.49 KB
/
mod_news.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Module UI
#' @title mod_news_ui and mod_news_server
#' @description A shiny Module.
#'
#' @param id shiny id
#' @param input internal
#' @param output internal
#' @param session internal
#'
#' @rdname mod_news
#'
#' @keywords internal
#' @export
#' @importFrom shiny NS tagList
mod_news_ui <- function(id){
ns <- NS(id)
tagList(
f7Block(
h2("News", class = "center"),
p(tags$small("Latest articles on the coronavirus."), class = "center"),
inset = TRUE
),
f7Block(uiOutput(ns("articles")))
)
}
# Module Server
#' @rdname mod_news
#' @export
#' @keywords internal
mod_news_server <- function(input, output, session, df){
ns <- session$ns
output$articles <- renderUI({
if(is.null(df))
return(span("No newsapi token"))
nws <- data.frame()
for(i in 1:nrow(df)){
if(i %% 2 == 0){
row <- df[i,]
nws <- dplyr::bind_rows(nws, row)
}
}
items <- nws %>%
dplyr::distinct() %>%
purrr::transpose() %>%
purrr::map(function(article){
f7ListItem(
title = article$title,
subtitle = substr(article$author, 1, 25),
tagList(
article$description,
),
media = tags$img(
src = article$urlToImage
),
footer = tags$a(
class = "link external article-link",
article$source,
href = article$url
)
)
})
f7List(mode = "media", items)
})
}