Last active
October 31, 2025 13:39
-
-
Save alekrutkowski/9c3a8ad583846b4460ec42271fecaeae to your computer and use it in GitHub Desktop.
R/Shiny app which (re)publishes an RSS feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Shiny app that serves a transformed RSS feed immediately at "/". | |
| # It fetches the source RSS on every request, appends a single space to the end | |
| # of each line, and returns it with the correct RSS content type so feed readers | |
| # can subscribe directly. | |
| # This particular app fixes the annoying problem in Inoreader, which concatenates | |
| # the words in the descriptions of new R packages. | |
| library(shiny) | |
| SOURCE_URL <- "https://dirk.eddelbuettel.com/cranberries/cran/new/index.rss" | |
| fetch_and_transform <- function(url = SOURCE_URL) { | |
| con <- | |
| url(url, "rb") | |
| on.exit(close(con), add = TRUE) | |
| lines <- | |
| c(paste0('<!-- ',Sys.time(),' -->'), | |
| readLines(con, warn = FALSE, encoding = "UTF-8")) | |
| paste0(lines, " ", collapse = "\n") | |
| } | |
| # UI is a function so we can return a raw HTTP response instead of HTML | |
| ui <- function() { | |
| content <- | |
| tryCatch(fetch_and_transform(), error = function(e) e) | |
| if (inherits(content, "error")) | |
| httpResponse( | |
| status = 502, | |
| content_type = "text/plain; charset=UTF-8", | |
| content = paste0("Upstream fetch failed: ", conditionMessage(content)) | |
| ) else | |
| httpResponse( | |
| status = 200, | |
| content_type = "application/rss+xml; charset=UTF-8", | |
| content = content | |
| ) | |
| } | |
| server <- function(input, output, session) {} | |
| shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment