Rows: 13 Columns: 26
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (9): place_of_publication, country_of_publication, general_area_of_cove...
dbl (4): title_id, free_text_information_about_dates_of_publication, lat, lng
lgl (13): nid, nlp, publication_title, edition, preceding_titles, succeeding...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
title_list$first_date_held <-as.numeric(title_list$first_date_held)title_list$last_date_held <-as.numeric(title_list$last_date_held)# coordinates_list = read_csv('newspaper_coordinates.csv')ui =fluidPage(titlePanel("Greek Map"),sidebarLayout(sidebarPanel =sidebarPanel(sliderInput('years', 'Years', min =20, max =1493, value =c(1, 1000))),mainPanel =mainPanel(leafletOutput(outputId ='map') ) ))
Warning: In sliderInput(): `value` should be greater than or equal to `min`
(value = 1, 1000, min = 20).
PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.
Shiny applications not supported in static R Markdown documents
Source Code
---title: Greek sitesserver: shinydate: 2024-09-17description: "..."image: delphi.pngtwitter-card: image: "delphi.png"open-graph: image: "delphi.png"categories: - misc---<!-- format: html --><!-- format: --><!-- html: --><!-- page-layout: custom --><!-- server: shiny -->```{r fig-gr-map, message = FALSE, warning=FALSE, echo=FALSE, fig.cap="Greek sites"}library(tidyverse)library(tidygeocoder)library(ggplot2)library(sf)library(rnaturalearth)library(mapview)library(dplyr)library(spatstat)library(leafpop)library(readxl)library(lubridate)gr <-read_excel("greek_sites.xlsx")# https://github.com/tidyverse/lubridate/issues/2parse_bce_ymd <-function(str) { regex <-"(\\d{4})(-\\d{2}-\\d{2})" match <- stringr::str_match(str, regex) years_n <- readr::parse_number(match[, 2]) -1# Beware the -1 here right_side <- match[, 3] date <-ymd(paste0("0000-",right_side)) -years(years_n)return(date)}gr$START <-parse_bce_ymd(gr$START)gr$END <-ymd(gr$END)gr_sf <- gr %>%st_as_sf(coords =c("LON", "LAT"),crs =st_crs("EPSG:2100") # CRS for Greece )grc =ne_countries(scale =50, returnclass ="sf") |>filter(admin =="Greece") mapData <-ne_countries(scale =10, continent =c("Europe"), returnclass ="sf")grc_states <-ne_states(country ="greece", returnclass ="sf")grc_states <- dplyr::select(grc_states, name, geometry)tr_states <-ne_states(country ="turkey", returnclass ="sf")st_crs(gr_sf) <-st_crs(grc)pp =st_geometry(gr_sf)window =st_geometry(grc)crs =st_crs("EPSG:2100") # CRS for Greecepp =st_transform(pp, crs)[!st_is_empty(pp)]window =st_transform(window, crs)wt =as.ppp(c(window, pp))# Smooth pointsdensity_spatstat <-density(wt, dimyx =500)# Convert density_spatstat into a stars object.density_stars <- stars::st_as_stars(density_spatstat)# Convert density_stars into an sf objectdensity_sf <-st_as_sf(density_stars) %>%st_set_crs(2100)gr_density <-ggplot() +geom_sf(data = density_sf, aes(fill = v), col =NA) +# scale_fill_viridis_c(option = "magma") +# scale_fill_gradientn(colours = c("grey80", "grey10")) +geom_sf(data =st_boundary(grc_states)) +geom_sf(data = gr_sf, shape =1,size =5, colour ="red", stroke =1, fill =NA) +theme_void() +theme(legend.position="none")# gr_densitymapview(gr_sf, col.regions ="lightblue", label ="PLACE",legend = T, layer.name ='Greek sites',map.types =c("CartoDB.Positron","CartoDB.DarkMatter"),popup =popupTable(gr_sf,zcol =c("CATEGORY","START","END","PLACE","GOD","POEM")))``````{r, include=FALSE, eval=FALSE}library(tidyverse)library(shiny)library(sf)library(leaflet)library(RColorBrewer)gr <-read_excel("greek_sites.xlsx")# https://github.com/tidyverse/lubridate/issues/2parse_bce_ymd <-function(str) { regex <-"(\\d{4})(-\\d{2}-\\d{2})" match <- stringr::str_match(str, regex) years_n <- readr::parse_number(match[, 2]) -1# Beware the -1 here right_side <- match[, 3] date <-ymd(paste0("0000-",right_side)) -years(years_n)return(date)}gr$START <-parse_bce_ymd(gr$START)gr$END <-ymd(gr$END)ui <-bootstrapPage( tags$style(type ="text/css", "html, body {width:100%;height:100%}"),leafletOutput("map", width ="100%", height ="100%"),absolutePanel(top =10, right =10,sliderInput("date", "Year", min(as.Date(gr$START)), max(as.Date(gr$END)),value=c(as.Date("-1099-01-01"), as.Date("1493-01-01"))# value = range(quakes$mag), step = 0.1 ),selectInput("colors", "Color Scheme",rownames(subset(brewer.pal.info, category %in%c("seq", "div"))) ),checkboxInput("legend", "Show legend", TRUE) ))server <-function(input, output, session) {# Reactive expression for the data subsetted to what the user selected filteredData <-reactive({ gr[gr$START >= input$date[1] & gr$END <= input$date[2],] })# This reactive expression represents the palette function,# which changes as the user makes selections in UI. colorpal <-reactive({colorNumeric(input$colors, range(min(as.Date(gr$START)), max(as.Date(gr$END)))) }) output$map <-renderLeaflet({# Use leaflet() here, and only include aspects of the map that# won't need to change dynamically (at least, not unless the# entire map is being torn down and recreated).leaflet(gr) %>%addTiles() %>%fitBounds(~min(LON), ~min(LAT), ~max(LON), ~max(LAT)) })# Incremental changes to the map (in this case, replacing the# circles when a new color is chosen) should be performed in# an observer. Each independent set of things that can change# should be managed in its own observer.observe({ pal <-colorpal()leafletProxy("map", data =filteredData()) %>%clearShapes() %>%addCircles(radius =~10^SIZE/10, weight =1, color ="#777777",fillColor =~pal(SIZE), fillOpacity =0.7, popup =~paste(SIZE) ) })# Use a separate observer to recreate the legend as needed.observe({ proxy <-leafletProxy("map", data = gr)# Remove any existing legend, and only if the legend is# enabled, create a new one. proxy %>%clearControls()if (input$legend) { pal <-colorpal() proxy %>%addLegend(position ="bottomright",pal = pal, values =~SIZE ) } })}shinyApp(ui, server)``````{r}library(tidyverse)library(shiny)library(sf)library(leaflet)# https://www.usit.uio.no/om/organisasjon/ffu/dht/aktiviteter/task/task-bloggen/rtv-map-tool.html# tap <- title_list %>%# # filter(first_date_held > input$years[1] & first_date_held < input$years[2]) %>%# # count(coverage_city, name = 'titles') %>%# left_join(coordinates_list, by = 'coverage_city')%>%# filter(!is.na(lng) & !is.na(lat)) %>%# st_as_sf(coords = c('lng', 'lat')) %>%# st_set_crs(2100)setwd("~/Documents/webpages/michaelczeller.github.io/blog/2024/09/17/greece/greek_tester")title_list =read_csv('BritishAndIrishNewspapersTitleList_20191118.csv')title_list$first_date_held <-as.numeric(title_list$first_date_held)title_list$last_date_held <-as.numeric(title_list$last_date_held)# coordinates_list = read_csv('newspaper_coordinates.csv')ui =fluidPage(titlePanel("Greek Map"),sidebarLayout(sidebarPanel =sidebarPanel(sliderInput('years', 'Years', min =20, max =1493, value =c(1, 1000))),mainPanel =mainPanel(leafletOutput(outputId ='map') ) ))server =function(input, output){ map_df =reactive({ title_list %>%filter(first_date_held > input$years[1] & first_date_held < input$years[2]) %>%# count(coverage_city, name = 'titles') %>%# left_join(coordinates_list, by = 'coverage_city')%>%filter(!is.na(lng) &!is.na(lat)) %>%st_as_sf(coords =c('lng', 'lat')) %>%st_set_crs(2100) }) output$map =renderLeaflet({leaflet() %>%addTiles() %>%setView(lng =25.5, lat =38.5, zoom =6) %>%addCircleMarkers(data = title_list,lng =~lng, lat =~lat,popup =paste("Place:", title_list$place_of_publication,"<br>", "God:", title_list$publisher, "<br>", "Poem:",'<a href=', title_list$explore_link, '>', "Click here",'</a>'))# , radius = ~sqrt(titles)) })}shinyApp(ui, server)```<!-- {{< video https://www.youtube.com/watch?v=EDxuMXb0joE >}} --><!-- > Wehrt euch, leistet Widerstand --><!-- > gegen den Faschismus hier im Land. --><!-- > Auf die Barrikaden, auf die Barrikaden! --><!-- You can download the data by clicking the button below. --><!-- ```{r echo = F, collapse = TRUE, comment = "#>", message = FALSE, warning=FALSE} --><!-- library(downloadthis) --><!-- antiAfD_geo_sf %>% download_this( --><!-- output_name = "compact_bwr", --><!-- output_extension = ".xlsx", --><!-- button_label = "Download dataset as xlsx", --><!-- button_type = "warning", --><!-- has_icon = TRUE, --><!-- icon = "fa fa-save" --><!-- ) --><!-- ``` --><!-- ****** --><!-- <span style="font-family:Garamond; font-size:0.8em;">The basic data is taken from the monitoring by the <a href="https://taz.de/">TAZ newspaper</a>, which has kept a monitor of the recent demonstrations against the AfD, available at <a href="https://taz.de/demo">https://taz.de/demo</a>.</a></span> -->