-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.Rmd
137 lines (102 loc) · 5.87 KB
/
test.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
title: "Untitled"
author: "Iwo Augustyński"
date: "17 12 2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r, echo=FALSE}
library(shiny)
library(eurostat)
library(dplyr)
library(tidyr)
library(plotly)
shinyApp(
## pobieranie danych
df <- get_eurostat("mips_sa")
df_l <- get_eurostat("mips_sa", type = "label") #already with full labels
labels <- df_l$indic_ip
names(labels) <- "labels"
df1 <- bind_cols(df, tibble::enframe(labels, name = NULL)) %>% rename(labels = value)
df2 <- df1 %>% filter(release == "SA19")
# Define UI for application
ui <- fluidPage(theme = "bootstrap.css",
## Pierwsza czesc opisu
fluidPage(
# includeMarkdown("mip.Rmd")
),
#######################
fluidRow( column (1), column (11,
selectInput("countries",
" Select country",
choices = list("Austria", "Belgium", "Bulgaria", "Cyprus", "Czechia", "Germany",
"Denmark", "Estonia", "Greece", "Spain", "Finland", "France", "Croatia", "Hungary", "Ireland",
"Italy", "Lithuania", "Luksembourg", "Latvia", "Malta", "Netherlands", "Poland",
"Portugal", "Romania", "Sweden", "Slovenia", "Slovakia"),
selected = "Poland"),
selectInput("indicator", "Select indicator",
choices = as.list(unique(as.character(df1$labels)), selected = "General government sector debt - % of GDP"))
)),
# Show a plot of the generated distribution
fluidRow(
plotlyOutput("distPlot", width = "100%", height = "600px")
#textOutput("text1"),
#textOutput("text2")
),
## Druga czesc opisu
fluidPage( "# Data and Reports"
# includeMarkdown("Bilanse-aneks.Rmd")
)
#######################
)
# matching full country names from the menu with abbreviations used in script.
countries <- tibble(geo = c("AT", "BE", "BG", "CY", "CZ", "DE", "DK",
"EE", "EL", "ES", "FI", "FR", "HR", "HU",
"IE", "IT", "LT", "LU", "LV", "MT", "NL",
"PL", "PT", "RO", "SE", "SI", "SK"),
geo1 = c("Austria", "Belgium", "Bulgaria", "Cyprus", "Czechia", "Germany",
"Denmark", "Estonia", "Greece", "Spain", "Finland", "France", "Croatia", "Hungary", "Ireland",
"Italy", "Lithuania", "Luksembourg", "Latvia", "Malta", "Netherlands", "Poland",
"Portugal", "Romania", "Sweden", "Slovenia", "Slovakia"))
colnames(countries) <- c("geo", "geo1")
# Define server logic required to draw a graph
server <- function(input, output) {
react<- reactive({countries %>% filter(geo1==input$countries) %>% select(geo) })
react.ind <- reactive({df2 %>% mutate(indic_ip = as.character(indic_ip)) %>% filter(labels==input$indicator) %>% select(indic_ip) %>% unique(.) })
#output$text1 <- renderText(as.character(countries %>% filter(geo1==input$countries) %>% select(geo)))
#output$text2 <- renderText(as.character(df2 %>% mutate(indic_ip = as.character(indic_ip)) %>% filter(labels==input$indicator) %>% select(indic_ip) %>% unique(.)))
output$distPlot <- renderPlotly({
ind <- df2 %>% mutate(indic_ip = as.character(indic_ip)) %>% filter(labels==input$indicator) %>% select(indic_ip) %>% unique(.)
tmp <- df2 %>% filter(indic_ip == as.character(ind))
tmp <- tmp %>% select(time, values, geo, labels)
country <- as.character(countries %>% filter(geo1==input$countries) %>% select(geo))
dfl <- tmp %>% mutate(selected = ifelse(geo==country, country,"EU"))
sel <- filter(dfl, geo ==country) #trick to have
unsel <- filter(dfl, geo !=country) #lines drawn in correct order. Otherwise sometimes red line is behind grey lines.
plot_ly() %>%
add_trace(x=unsel$time, y=unsel$values, type = "scatter", mode = "lines", split = unsel$geo, color = unsel$selected, line = list(color = "lightgrey"),
text = paste("Country: ", unsel$geo,
"<br>Value: ", round(unsel$values, digits = 2),
"<br>Date: ", unsel$time),
hoverinfo = 'text') %>%
add_trace(x = sel$time, y=sel$values, mode = "lines", line = list(color = "#00c0ef"),
text = paste("Country: ", sel$geo,
"<br>Value: ", round(sel$values, digits = 2),
"<br>Date: ", sel$time),
hoverinfo = 'text') %>%
layout(showlegend = FALSE, title = labels[1], xaxis = list(title = ""), yaxis = list(title = ""))
})
}
)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.