Last active
March 6, 2025 13:26
-
-
Save alekrutkowski/992b37583bd6393afc764e314e53f5b3 to your computer and use it in GitHub Desktop.
An R/Shiny app for viewing the Eurostat MetaBase table
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
library(shiny) | |
library(DT) | |
library(shinycssloaders) | |
library(magrittr) | |
library(data.table) | |
library(eurodata) | |
ui <- fluidPage( | |
titlePanel(HTML(paste0('<a href="https://ec.europa.eu/eurostat/api/dissemination/catalogue/metabase.txt.gz?labels=no"', | |
'target="_blank">Eurostat Metabase</a> Table')), | |
windowTitle='Metabase Viewer'), | |
h4(HTML(paste0('🛈 You can use the ', | |
'<a href="https://en.wikipedia.org/wiki/Regular_expression#Basic_concepts"', | |
'target="_blank">regex</a> in the search/filter fields.'))), | |
withSpinner(DTOutput("dataTable")) | |
) | |
server <- function(input, output, session) { | |
# Reactive expression to load the data once at startup | |
data <- reactive({ | |
eurodata::importMetabase() %>% | |
setDT() %>% | |
.[, Code := paste0('<a href="https://ec.europa.eu/eurostat/databrowser/view/', | |
Code,'/default/table" target="_blank">',Code,'</a>')] | |
}) | |
# Render the data table with filters at the top | |
output$dataTable <- renderDT( | |
datatable(data(), | |
escape = FALSE, | |
filter = "top", | |
extensions = 'Buttons', # Enables export buttons | |
options = list(pageLength=25, | |
lengthMenu = list(c(25, 100, -1), c("25", "100", "All")), # Dropdown for selecting number of rows | |
search = list(regex = TRUE), | |
scroller=TRUE, | |
paging = TRUE, # Disables pagination | |
dom = 'Blfrtip', # Adds buttons above the table | |
buttons = list( | |
list(extend = 'csv', text = 'Download Filtered CSV', | |
exportOptions = list(modifier = list(page = "all"))), | |
list(extend = 'excel', text = 'Download Filtered Excel', | |
exportOptions = list(modifier = list(page = "all")))) | |
) | |
)) | |
} | |
# Run the application | |
shinyApp(ui, server) %>% `if`(interactive(), runApp(.), .) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment