From 9ae7f94e636efc06d38452aa480bd18275c8c7f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ad=C3=A9la=20Drabinov=C3=A1?= Date: Thu, 17 Aug 2017 11:47:06 +0200 Subject: [PATCH 1/5] CRANview update See NEWS file --- NEWS | 14 ++++++++ README.md | 3 +- server.R | 98 +++++++++++++++++++++++++++++++++++++++++++------------ ui.R | 18 +++++++--- 4 files changed, 107 insertions(+), 26 deletions(-) create mode 100644 NEWS diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..fc0d1df --- /dev/null +++ b/NEWS @@ -0,0 +1,14 @@ + *************************************************** + * * + * Changes and Developments in the CRAN view app * + * * + *************************************************** + +------------------------------------ +- Changes in CRANview (2017-08-17) - +------------------------------------ + + o Package 'plotly' is now used for the plot to make app more + interactive. + o Date range was added. + o Some information about selected packages is now provided. \ No newline at end of file diff --git a/README.md b/README.md index c3c6588..6d7ede0 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,5 @@ View CRAN Package Downloads with Shiny A Shiny app to visualize downloads from RStudio's CRAN mirror. -View the app [here](https://dgrtwo.shinyapps.io/cranview/), or read more about it [here](http://varianceexplained.org/r/cran-view). +View the app [here](https://dgrtwo.shinyapps.io/cranview/), or read more about it +[here](http://varianceexplained.org/r/cran-view). diff --git a/server.R b/server.R index ed1286c..04de091 100644 --- a/server.R +++ b/server.R @@ -6,6 +6,7 @@ library(lubridate) library(cranlogs) library(zoo) library(scales) +library(plotly) get_initial_release_date = function(packages) { @@ -24,28 +25,83 @@ get_initial_release_date = function(packages) min_date } -shinyServer(function(input, output) { - downloads <- reactive({ - packages <- input$package - cran_downloads0 <- failwith(NULL, cran_downloads, quiet = TRUE) - cran_downloads0(package = packages, - from = get_initial_release_date(packages), - to = Sys.Date()-1) - }) +get_some_info = function(packages) +{ + info <- list() + for (pkg in packages) + { + # api data for package. we want the initial release - the first element of the "timeline" + pkg_data = httr::GET(paste0("http://crandb.r-pkg.org/", pkg, "/all")) + pkg_data = httr::content(pkg_data) + + info[[pkg]]$title <- pkg_data$title + info[[pkg]]$version <- pkg_data$latest + info[[pkg]]$cran <- paste("https://CRAN.R-project.org/package=", pkg, sep = "") + } + + info +} + + +shinyServer(function(input, output, session) { + + observe({ + release_date <- min(get_initial_release_date(input$package)) + updateDateRangeInput(session, "dateRange", + label = "Date range: yyyy-mm-dd", + start = release_date, + end = Sys.Date()-1, + max = Sys.Date()) + }) - output$downloadsPlot <- renderPlot({ - d <- downloads() - if (input$transformation=="weekly") { - d$count=rollapply(d$count, 7, sum, fill=NA) - } else if (input$transformation=="cumulative") { - d = d %>% - group_by(package) %>% - transmute(count=cumsum(count), date=date) - } - ggplot(d, aes(date, count, color = package)) + geom_line() + - xlab("Date") + - scale_y_continuous(name="Number of downloads", labels = comma) - }) + downloads <- reactive({ + packages <- input$package + cran_downloads0 <- failwith(NULL, cran_downloads, quiet = TRUE) + cran_downloads0(package = packages, + from = input$dateRange[1], + to = input$dateRange[2]) + }) + + + output$downloadsPlot <- renderPlotly({ + d <- downloads() + packages <- input$package + packages <- packages[order(packages)] + if (input$transformation == "weekly") { + d$count = rollapply(d$count, 7, sum, fill = NA) + } else if (input$transformation == "cumulative") { + d = d %>% + group_by(package) %>% + transmute(count = cumsum(count), date = date) + } + g <- ggplot(d, aes(date, count, color = package)) + + geom_line() + + xlab("Date") + + scale_y_continuous(name = "Number of downloads", labels = comma) + g <- ggplotly(g) %>% config(displayModeBar = F) + + for (i in 1:length(packages)){ + g$x$data[[i]]$text <- paste("date:", d$date[d$package == packages[i]], + "
count:", d$count[d$package == packages[i]], + "
package:", packages[i]) + } + g + }) + + output$packageinfo <- renderUI({ + packages <- input$package + info <- get_some_info(packages) + text <- "" + for (pkg in packages) + { + text <- paste(text, + paste("", pkg, "", + "
Title: ", info[[pkg]]$title, + "
Latest version: ", info[[pkg]]$version, "
", + sep = "")) + } + HTML(text) + }) }) diff --git a/ui.R b/ui.R index 23b527a..a503ac7 100644 --- a/ui.R +++ b/ui.R @@ -1,6 +1,7 @@ library(shiny) library(httr) library(jsonlite) +library(plotly) # get the list of all packages on CRAN package_names = names(httr::content(httr::GET("http://crandb.r-pkg.org/-/desc"))) @@ -8,30 +9,39 @@ package_names = names(httr::content(httr::GET("http://crandb.r-pkg.org/-/desc")) shinyUI(fluidPage( # Application title - titlePanel("Package Downloads Over Time"), + titlePanel("Package CRAN downloads over time"), # Sidebar with a slider input for number of bins sidebarLayout( sidebarPanel( HTML("Enter an R package to see the # of downloads over time from the RStudio CRAN Mirror.", "You can enter multiple packages to compare them"), + br(), + br(), selectInput("package", label = "Packages:", selected = sample(package_names, 2), # initialize the graph with a random package choices = package_names, - multiple = TRUE), + multiple = TRUE), radioButtons("transformation", "Data Transformation:", c("Daily" = "daily", "Weekly" = "weekly", "Cumulative" = "cumulative")), + + dateRangeInput("dateRange", + label = 'Date range: yyyy-mm-dd', + start = Sys.Date() - 2, end = Sys.Date() - 1, max = Sys.Date()), + HTML("Created using the cranlogs package.", "This app is not affiliated with RStudio or CRAN.", - "You can find the code for the app here,", + "This is an updated version of original app.", + "You can find the code for the app here,", "or read more about it here.") ), # Show a plot of the generated distribution mainPanel( - plotOutput("downloadsPlot") + plotlyOutput("downloadsPlot"), + htmlOutput("packageinfo") ) ) )) From 1e134ff85673f836eec639e9bc718328f699d1ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ad=C3=A9la=20Drabinov=C3=A1?= Date: Thu, 17 Aug 2017 11:52:53 +0200 Subject: [PATCH 2/5] Info update --- ui.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui.R b/ui.R index a503ac7..a804817 100644 --- a/ui.R +++ b/ui.R @@ -33,8 +33,7 @@ shinyUI(fluidPage( HTML("Created using the cranlogs package.", "This app is not affiliated with RStudio or CRAN.", - "This is an updated version of original app.", - "You can find the code for the app here,", + "You can find the code for the app here,", "or read more about it here.") ), From 3c9aad1cf1a92cd932818e7c3c37436c4be322d5 Mon Sep 17 00:00:00 2001 From: adelahladka Date: Fri, 19 Feb 2021 05:49:16 +0100 Subject: [PATCH 3/5] update --- server.R | 2 +- ui.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server.R b/server.R index 04de091..2db7874 100644 --- a/server.R +++ b/server.R @@ -57,7 +57,7 @@ shinyServer(function(input, output, session) { downloads <- reactive({ packages <- input$package - cran_downloads0 <- failwith(NULL, cran_downloads, quiet = TRUE) + cran_downloads0 <- purrr::possibly(cran_downloads, otherwise = NULL, quiet = TRUE) cran_downloads0(package = packages, from = input$dateRange[1], to = input$dateRange[2]) diff --git a/ui.R b/ui.R index a804817..c100f94 100644 --- a/ui.R +++ b/ui.R @@ -20,7 +20,7 @@ shinyUI(fluidPage( br(), selectInput("package", label = "Packages:", - selected = sample(package_names, 2), # initialize the graph with a random package + selected = c("difNLR", "ShinyItemAnalysis"), # initialize the graph with a random package choices = package_names, multiple = TRUE), radioButtons("transformation", From dcff45f1fd8deb077a3b65eed6b01db07ccaaff1 Mon Sep 17 00:00:00 2001 From: adelahladka Date: Fri, 19 Feb 2021 13:34:22 +0100 Subject: [PATCH 4/5] update --- server.R | 178 ++++++++++++++++++++++++++++--------------------------- ui.R | 47 +++++++++------ 2 files changed, 119 insertions(+), 106 deletions(-) diff --git a/server.R b/server.R index 2db7874..861ff19 100644 --- a/server.R +++ b/server.R @@ -8,100 +8,104 @@ library(zoo) library(scales) library(plotly) -get_initial_release_date = function(packages) -{ - min_date = Sys.Date() - 1 - - for (pkg in packages) - { - # api data for package. we want the initial release - the first element of the "timeline" - pkg_data = httr::GET(paste0("http://crandb.r-pkg.org/", pkg, "/all")) - pkg_data = httr::content(pkg_data) - - initial_release = pkg_data$timeline[[1]] - min_date = min(min_date, as.Date(initial_release)) - } - - min_date +get_initial_release_date <- function(packages) { + min_date <- Sys.Date() - 1 + + for (pkg in packages) + { + # api data for package. we want the initial release - the first element of the "timeline" + pkg_data <- httr::GET(paste0("http://crandb.r-pkg.org/", pkg, "/all")) + pkg_data <- httr::content(pkg_data) + + initial_release <- pkg_data$timeline[[1]] + min_date <- min(min_date, as.Date(initial_release)) + } + + min_date } -get_some_info = function(packages) -{ - info <- list() - for (pkg in packages) - { - # api data for package. we want the initial release - the first element of the "timeline" - pkg_data = httr::GET(paste0("http://crandb.r-pkg.org/", pkg, "/all")) - pkg_data = httr::content(pkg_data) - - info[[pkg]]$title <- pkg_data$title - info[[pkg]]$version <- pkg_data$latest - info[[pkg]]$cran <- paste("https://CRAN.R-project.org/package=", pkg, sep = "") - } - - info +get_some_info <- function(packages) { + info <- list() + for (pkg in packages) + { + # api data for package. we want the initial release - the first element of the "timeline" + pkg_data <- httr::GET(paste0("http://crandb.r-pkg.org/", pkg, "/all")) + pkg_data <- httr::content(pkg_data) + + info[[pkg]]$title <- pkg_data$title + info[[pkg]]$version <- pkg_data$latest + info[[pkg]]$cran <- paste("https://CRAN.R-project.org/package=", pkg, sep = "") + } + + info } shinyServer(function(input, output, session) { + observe({ + release_date <- min(get_initial_release_date(input$package)) + updateDateRangeInput(session, "dateRange", + label = "Date range: yyyy-mm-dd", + start = release_date, + end = Sys.Date() - 1, + max = Sys.Date() + ) + }) + - observe({ - release_date <- min(get_initial_release_date(input$package)) - updateDateRangeInput(session, "dateRange", - label = "Date range: yyyy-mm-dd", - start = release_date, - end = Sys.Date()-1, - max = Sys.Date()) - }) - + downloads <- reactive({ + packages <- input$package + cran_downloads0 <- purrr::possibly(cran_downloads, otherwise = NULL, quiet = TRUE) + cran_downloads0( + package = packages, + from = input$dateRange[1], + to = input$dateRange[2] + ) + }) - downloads <- reactive({ - packages <- input$package - cran_downloads0 <- purrr::possibly(cran_downloads, otherwise = NULL, quiet = TRUE) - cran_downloads0(package = packages, - from = input$dateRange[1], - to = input$dateRange[2]) - }) - - - output$downloadsPlot <- renderPlotly({ - d <- downloads() - packages <- input$package - packages <- packages[order(packages)] - if (input$transformation == "weekly") { - d$count = rollapply(d$count, 7, sum, fill = NA) - } else if (input$transformation == "cumulative") { - d = d %>% - group_by(package) %>% - transmute(count = cumsum(count), date = date) - } - g <- ggplot(d, aes(date, count, color = package)) + - geom_line() + - xlab("Date") + - scale_y_continuous(name = "Number of downloads", labels = comma) - g <- ggplotly(g) %>% config(displayModeBar = F) - - for (i in 1:length(packages)){ - g$x$data[[i]]$text <- paste("date:", d$date[d$package == packages[i]], - "
count:", d$count[d$package == packages[i]], - "
package:", packages[i]) - } - g - }) - - output$packageinfo <- renderUI({ - packages <- input$package - info <- get_some_info(packages) - text <- "" - for (pkg in packages) - { - text <- paste(text, - paste("", pkg, "", - "
Title: ", info[[pkg]]$title, - "
Latest version: ", info[[pkg]]$version, "
", - sep = "")) - } - HTML(text) - }) + output$downloadsPlot <- renderPlotly({ + d <- downloads() + packages <- input$package + packages <- packages[order(packages)] + if (input$transformation == "weekly") { + d$count <- rollapply(d$count, 7, sum, fill = NA) + } else if (input$transformation == "cumulative") { + d <- d %>% + group_by(package) %>% + transmute(count = cumsum(count), date = date) + } + g <- ggplot(d, aes(date, count, color = package)) + + geom_line() + + xlab("Date") + + scale_y_continuous(name = "Number of downloads", labels = comma) + g <- ggplotly(g) %>% config(displayModeBar = FALSE) + + for (i in 1:length(packages)) { + g$x$data[[i]]$text <- paste( + "date:", d$date[d$package == packages[i]], + "
count:", d$count[d$package == packages[i]], + "
package:", packages[i] + ) + } + g + }) + + output$packageinfo <- renderUI({ + packages <- input$package + info <- get_some_info(packages) + text <- "" + for (pkg in packages) + { + text <- paste( + text, + paste("", pkg, "", + "
Title: ", info[[pkg]]$title, + "
Latest version: ", info[[pkg]]$version, "
", + sep = "" + ) + ) + } + HTML(text) + }) }) diff --git a/ui.R b/ui.R index c100f94..6c834cd 100644 --- a/ui.R +++ b/ui.R @@ -4,7 +4,7 @@ library(jsonlite) library(plotly) # get the list of all packages on CRAN -package_names = names(httr::content(httr::GET("http://crandb.r-pkg.org/-/desc"))) +package_names <- names(httr::content(httr::GET("http://crandb.r-pkg.org/-/desc"))) shinyUI(fluidPage( @@ -14,27 +14,36 @@ shinyUI(fluidPage( # Sidebar with a slider input for number of bins sidebarLayout( sidebarPanel( - HTML("Enter an R package to see the # of downloads over time from the RStudio CRAN Mirror.", - "You can enter multiple packages to compare them"), + HTML( + "Enter an R package to see the # of downloads over time from the RStudio CRAN Mirror.", + "You can enter multiple packages to compare them" + ), br(), br(), - selectInput("package", - label = "Packages:", - selected = c("difNLR", "ShinyItemAnalysis"), # initialize the graph with a random package - choices = package_names, - multiple = TRUE), - radioButtons("transformation", - "Data Transformation:", - c("Daily" = "daily", "Weekly" = "weekly", "Cumulative" = "cumulative")), - + selectInput("package", + label = "Packages:", + selected = c("difNLR", "ShinyItemAnalysis"), # initialize the graph with a random package + choices = package_names, + multiple = TRUE, + selectize = TRUE + ), + radioButtons("transformation", + "Data Transformation:", + c("Daily" = "daily", "Weekly" = "weekly", "Cumulative" = "cumulative"), + selected = "cumulative" + ), + dateRangeInput("dateRange", - label = 'Date range: yyyy-mm-dd', - start = Sys.Date() - 2, end = Sys.Date() - 1, max = Sys.Date()), - - HTML("Created using the cranlogs package.", - "This app is not affiliated with RStudio or CRAN.", - "You can find the code for the app here,", - "or read more about it here.") + label = "Date range: yyyy-mm-dd", + start = Sys.Date() - 2, end = Sys.Date() - 1, max = Sys.Date() + ), + + HTML( + "Created using the cranlogs package.", + "This app is not affiliated with RStudio or CRAN.", + "You can find the code for the app here,", + "or read more about it here." + ) ), # Show a plot of the generated distribution From 05fba8815bcc45409d8f3b94c0299598d1bf3980 Mon Sep 17 00:00:00 2001 From: adelahladka Date: Fri, 19 Feb 2021 13:58:52 +0100 Subject: [PATCH 5/5] Update ui.R --- ui.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ui.R b/ui.R index 6c834cd..0f7a198 100644 --- a/ui.R +++ b/ui.R @@ -20,12 +20,11 @@ shinyUI(fluidPage( ), br(), br(), - selectInput("package", + selectizeInput("package", label = "Packages:", selected = c("difNLR", "ShinyItemAnalysis"), # initialize the graph with a random package choices = package_names, - multiple = TRUE, - selectize = TRUE + multiple = TRUE ), radioButtons("transformation", "Data Transformation:",