Compare commits

...

2 Commits

Author SHA1 Message Date
lewy
7fc229bc24 Merge branch 'master' of https://git.wmi.amu.edu.pl/s444427/UE_house_prices_wizualizacja 2023-06-14 12:48:12 +02:00
lewy
82af00dec6 ADD About 2023-06-14 12:47:55 +02:00

204
webapp.R
View File

@ -2,114 +2,138 @@ library(shiny)
library(leaflet) library(leaflet)
library(ggplot2) library(ggplot2)
library(dplyr) library(dplyr)
library(shinyalert)
library(DT)
# install.packages("DT")
# Frontend # Frontend
ui <- fluidPage( ui <- fluidPage(
sidebarLayout(
sidebarPanel(
# Compound interest
sliderInput("range", "Compound interest:",min = 0, max = 10, value = c(4,8)),textOutput("Compound interest slider"),
# Checkboxes
#tags$head(tags$style(HTML(".checkbox {margin-left:15px}"))),
checkboxGroupInput("countries", "Chosen countries:",
choiceNames = c(map_df$region),
choiceValues = c(map_df$geo),
selected = c("PL", "CZ", "DE"),
inline = TRUE,
width = "75%"
),
width=3 sidebarLayout(
sidebarPanel(
# Compound interest
sliderInput("range", "Compound interest:",min = 0, max = 10, value = c(4,8)),textOutput("Compound interest slider"),
# Checkboxes
#tags$head(tags$style(HTML(".checkbox {margin-left:15px}"))),
checkboxGroupInput("countries", "Chosen countries:",
choiceNames = c(map_df$region),
choiceValues = c(map_df$geo),
selected = c("PL", "CZ", "DE"),
inline = TRUE,
width = "75%"
), ),
mainPanel( # About
h1("Real house prices index"), useShinyalert(),
actionButton("about", "?"),
tabsetPanel(
tabPanel("Plot", plotlyOutput("final_plot")),
tabPanel("Map", leafletOutput("mymap")),
tabPanel("Table", dataTableOutput('table'))
),
width = 9
),
fluid = TRUE
) width=3
),
mainPanel(
h1("Real house prices index"),
tabsetPanel(
tabPanel("Plot", plotlyOutput("final_plot")),
tabPanel("Map", leafletOutput("mymap")),
tabPanel("Table", dataTableOutput('table'))
),
width = 9
),
fluid = TRUE
)
) )
# Backend # Backend
server <- function(input, output, session) { server <- function(input, output, session) {
output$table <- renderDataTable({ observeEvent(input$about, {
merged_df[, !names(merged_df) %in% c("OBS_VALUE.x", "OBS_VALUE.y", "geometry")] # Show a modal when the button is pressed
}, options = list(pageLength = 10)) shinyalert("About project:",
"Authors: Paweł Lewicki, Patryk Kaszuba\n
The aim of the project is to present growth of house prices as index of Purchasing Power Parity (PPP) in countries of European Union. 2015 is a benchmark value (100 for each country).
# Plot module Datasets used:
output$final_plot <- renderPlotly({ - Eurostat Inflation 2022 - prc_hicp_aind_page_linear
final_plot <- ggplot(filter(merged_df, geo %in% input$countries), - Eurostat House Price Index - prc_hpi_a__custom_3617733_page_linear
aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo,
text = paste("Kraj: ", geo, "<br>", "Rok: ", TIME_PERIOD, "<br>", Libraries used:
"Cena nieruchomości: ", house_prices_wo_hicp))) + shiny, leaflet, ggplot2, dplyr, shinyalert, plotly, dplyr,
geom_line(aes(group = geo), linetype = "dotted", size = 1) + tidyverse, eurostat, sf, scales, cowplot, ggthemes, RColorBrewer
geom_point() +
geom_text(data = filter(merged_df, geo %in% input$countries) %>% group_by(geo) %>% slice(n()), Subject: Data Wizualisation
aes(label = "", hjust = -0.2, size = 4)) + Adam Mickiewicz University,
stat_function(fun = function(x) 100*(1+input$range[1]/100)^(x-2015), aes(colour = paste0(as.character(input$range[1]), "% Compounding")), inherit.aes = FALSE) + Poznan, Poland, June 2023"
stat_function(fun = function(x) 100*(1+input$range[2]/100)^(x-2015), aes(colour = paste0(as.character(input$range[2]), "% Compounding")), inherit.aes = FALSE) + , type = "info")
scale_x_continuous(breaks = seq(2010, 2024, 2)) + })
labs(x = "Rok", y = "Indeks cen nieruchomości zdyskontowany o wartość inflacji [2015 = 100]",
color = "Countries") + output$table <- DT::renderDataTable({
theme(axis.title = element_blank()) datatable(merged_df[, !names(merged_df) %in% c("OBS_VALUE.x", "OBS_VALUE.y", "geometry")], options = list(pageLength = 10))
})
plotly_plot <- ggplotly(final_plot, tooltip = "text")
for (i in 1:length(plotly_plot$x$data)) { # Plot module
if (plotly_plot$x$data[[i]]$name == paste0(as.character(input$range[1]), "% Compounding") || plotly_plot$x$data[[i]]$name == paste0(as.character(input$range[1]), "% Compounding")) { output$final_plot <- renderPlotly({
plotly_plot$x$data[[i]]$hoverinfo <- "name+y" final_plot <- ggplot(filter(merged_df, geo %in% input$countries),
} aes(x = TIME_PERIOD, y = house_prices_wo_hicp, color = geo,
text = paste("Kraj: ", geo, "<br>", "Rok: ", TIME_PERIOD, "<br>",
"Cena nieruchomości: ", house_prices_wo_hicp))) +
geom_line(aes(group = geo), linetype = "dotted", size = 1) +
geom_point() +
geom_text(data = filter(merged_df, geo %in% input$countries) %>% group_by(geo) %>% slice(n()),
aes(label = "", hjust = -0.2, size = 4)) +
stat_function(fun = function(x) 100*(1+input$range[1]/100)^(x-2015), aes(colour = paste0(as.character(input$range[1]), "% Compounding")), inherit.aes = FALSE) +
stat_function(fun = function(x) 100*(1+input$range[2]/100)^(x-2015), aes(colour = paste0(as.character(input$range[2]), "% Compounding")), inherit.aes = FALSE) +
scale_x_continuous(breaks = seq(2010, 2024, 2)) +
labs(x = "Rok", y = "Indeks cen nieruchomości zdyskontowany o wartość inflacji [2015 = 100]",
color = "Countries") +
theme(axis.title = element_blank())
plotly_plot <- ggplotly(final_plot, tooltip = "text")
for (i in 1:length(plotly_plot$x$data)) {
if (plotly_plot$x$data[[i]]$name == paste0(as.character(input$range[1]), "% Compounding") || plotly_plot$x$data[[i]]$name == paste0(as.character(input$range[1]), "% Compounding")) {
plotly_plot$x$data[[i]]$hoverinfo <- "name+y"
} }
}
plotly_plot %>% layout(showlegend = TRUE, legend = list(title = list(text = "Countries")))
})
# Map module
output$mymap <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addPolygons(data=mapdata_new,
fillOpacity = 0.6, # Przezroczystość
stroke = TRUE, # Borders visible
color = "grey", # Border color
weight = 1,
fillColor = ~qpal(mapdata_new$substr_house_prices_wo_hicp),
popup = popup_content,
popupOptions = popupOptions(maxWidth ="100%", closeOnClick = TRUE)
) %>%
setView( lat = 49, lng = 14, zoom = 4) %>%
addLegend("bottomright", colors = qpal_colors,
title = "<span style='white-space: pre-line;'> Real house prices \n index (2022) </span>",
labels = qpal_labs,
opacity = 1)
}) # End of map module
plotly_plot %>% layout(showlegend = TRUE, legend = list(title = list(text = "Countries")))
})
# Map module
output$mymap <- renderLeaflet({
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addPolygons(data=mapdata_new,
fillOpacity = 0.6, # Przezroczystość
stroke = TRUE, # Borders visible
color = "grey", # Border color
weight = 1,
fillColor = ~qpal(mapdata_new$substr_house_prices_wo_hicp),
popup = popup_content,
popupOptions = popupOptions(maxWidth ="100%", closeOnClick = TRUE)
) %>%
setView( lat = 49, lng = 14, zoom = 4) %>%
addLegend("bottomright", colors = qpal_colors,
title = "<span style='white-space: pre-line;'> Real house prices \n index (2022) </span>",
labels = qpal_labs,
opacity = 1)
}) # End of map module
}# End of server }# End of server
# Run # Run