Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
130 changes: 95 additions & 35 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,106 @@ library(lubridate)
library(cranlogs)
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
}

shinyServer(function(input, output) {
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()
)
})


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)
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 <- 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)


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]],
"<br>count:", d$count[d$package == packages[i]],
"<br>package:", packages[i]
)
}
g
})

output$packageinfo <- renderUI({
packages <- input$package
info <- get_some_info(packages)
text <- ""
for (pkg in packages)
{
text <- paste(
text,
paste("<a href='https://CRAN.R-project.org/package=", pkg, "'>", pkg, "</a>",
"<br>Title: ", info[[pkg]]$title,
"<br>Latest version: ", info[[pkg]]$version, "<br>",
sep = ""
)
)
}
HTML(text)
})
})
51 changes: 34 additions & 17 deletions ui.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
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")))
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"),
selectInput("package",
label = "Packages:",
selected = sample(package_names, 2), # initialize the graph with a random package
choices = package_names,
multiple = TRUE),
radioButtons("transformation",
"Data Transformation:",
c("Daily" = "daily", "Weekly" = "weekly", "Cumulative" = "cumulative")),
HTML("Created using the <a href='https://github.com/metacran/cranlogs'>cranlogs</a> package.",
"This app is not affiliated with RStudio or CRAN.",
"You can find the code for the app <a href='https://github.com/dgrtwo/cranview'>here</a>,",
"or read more about it <a href='http://varianceexplained.org/r/cran-view/'>here</a>.")
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(),
selectizeInput("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"),
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 <a href='https://github.com/metacran/cranlogs'>cranlogs</a> package.",
"This app is not affiliated with RStudio or CRAN.",
"You can find the code for the app <a href='https://github.com/dgrtwo/cranview'>here</a>,",
"or read more about it <a href='http://varianceexplained.org/r/cran-view/'>here</a>."
)
),

# Show a plot of the generated distribution
mainPanel(
plotOutput("downloadsPlot")
plotlyOutput("downloadsPlot"),
htmlOutput("packageinfo")
)
)
))