---
title: "eDesk"
output: 
  flexdashboard::flex_dashboard:
    social: menu
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(DT)
library(tidyverse)
library(readxl)
library(corrplot)
library(stringr)
library(bsselectR)

podaci <- read_excel('podaci.xlsx', sheet=1)
imena <- names(podaci)
podaci <- podaci %>% rename_with(.fn = ~paste0("Q", substring(.,1,regexpr("\\.", .) - 1)), .cols = 9:length(imena))
pitanja <- podaci %>% select(Q1:Q67)

kodovi_pitanja = data.frame(kod=names(pitanja), pitanje=imena[9:length(imena)])
korelacije <- round(cor(pitanja, use = "pairwise.complete.obs"), 2)

pitanja_Croatia <- podaci %>% filter(Country == 'Croatia') %>% select(Q1:Q67)
korelacije_Croatia <- round(cor(pitanja_Croatia, use = "pairwise.complete.obs"), 2)

pitanja_Finland <- podaci %>% filter(Country == 'Finland') %>% select(Q1:Q67)
korelacije_Finland <- round(cor(pitanja_Finland, use = "pairwise.complete.obs"), 2)

pitanja_Portugal <- podaci %>% filter(Country == 'Portugal') %>% select(Q1:Q67)
korelacije_Portugal <- round(cor(pitanja_Portugal, use = "pairwise.complete.obs"), 2)

pitanja_Spain <- podaci %>% filter(Country == 'Spain') %>% select(Q1:Q67)
korelacije_Spain <- round(cor(pitanja_Spain, use = "pairwise.complete.obs"), 2)

kodovi_pitanja = data.frame(kod=names(pitanja), pitanje=imena[9:length(imena)])

slike1 <- list.files("slike1",full.names = TRUE)
names(slike1) <- str_replace_all(slike1, c("_pitCo\\.png" = "", "slike1/" = ""))

slike2 <- list.files("slike2",full.names = TRUE)
names(slike2) <- str_replace_all(slike2, c("_coPit\\.png" = "", "slike2/" = ""))
```

pitanja
=======================================================================

```{r}
datatable(
  kodovi_pitanja, extensions = c('Scroller'),
  options = list(deferRender = TRUE, scrollY = 200, scroller = TRUE))
```

mozaik 1
=======================================================================

Column {data-width=450}
-----------------------------------------------------------------------

### pitanje - država

```{r}
bsselect(slike1, type = "img", selected = "Q1", live_search = TRUE, show_tick = TRUE)
```

Column {data-width=450}
-----------------------------------------------------------------------

### pitanje - država

```{r}
bsselect(slike1, type = "img", selected = "Q1", live_search = TRUE, show_tick = TRUE)
```

mozaik 2
=======================================================================

Column {data-width=450}
-----------------------------------------------------------------------

### država - pitanje

```{r}
bsselect(slike2, type = "img", selected = "Q1", live_search = TRUE, show_tick = TRUE)
```

Column {data-width=450}
-----------------------------------------------------------------------

### država - pitanje

```{r}
bsselect(slike2, type = "img", selected = "Q1", live_search = TRUE, show_tick = TRUE)
```

mozaik 3
=======================================================================

Column {data-width=450}
-----------------------------------------------------------------------

### pitanje - država

```{r}
bsselect(slike1, type = "img", selected = "Q1", live_search = TRUE, show_tick = TRUE)
```

Column {data-width=450}
-----------------------------------------------------------------------

### država - pitanje

```{r}
bsselect(slike2, type = "img", selected = "Q1", live_search = TRUE, show_tick = TRUE)
```

korelacije - sve države
=======================================================================

Column {data-width=450}
-----------------------------------------------------------------------

### grafički prikaz korelacija

```{r}
corrplot(korelacije, type = "upper", tl.col = "black", tl.srt = 90,
         diag=FALSE, mar=c(0,0,0.1,0), tl.cex=0.4)
```

Column {data-width=350}
-----------------------------------------------------------------------

### Tablica korelacija

```{r}
datatable(korelacije, filter = 'top',
    extensions = c('FixedColumns','Select', 'Buttons'),
    options = list(
      dom = 'Blfrtip',
      select = list(style = 'os', items = 'row'),
      buttons = c('selectAll', 'selectNone', 'selectRows', 'selectColumns', 'selectCells'),
      pageLength = 15,
      scrollX = TRUE,
      fixedColumns = TRUE
    )
)
```

korelacije - Hrvatska
=======================================================================

Column {data-width=450}
-----------------------------------------------------------------------

### grafički prikaz korelacija

```{r}
corrplot(korelacije_Croatia, type = "upper", tl.col = "black", tl.srt = 90,
         diag=FALSE, mar=c(0,0,0.1,0), tl.cex=0.4)
```

Column {data-width=350}
-----------------------------------------------------------------------

### Tablica korelacija

```{r}
datatable(korelacije_Croatia, filter = 'top',
    extensions = c('FixedColumns','Select', 'Buttons'),
    options = list(
      dom = 'Blfrtip',
      select = list(style = 'os', items = 'row'),
      buttons = c('selectAll', 'selectNone', 'selectRows', 'selectColumns', 'selectCells'),
      pageLength = 15,
      scrollX = TRUE,
      fixedColumns = TRUE
    )
)
```

korelacije - Finska
=======================================================================

Column {data-width=450}
-----------------------------------------------------------------------

### grafički prikaz korelacija

```{r}
corrplot(korelacije_Finland, type = "upper", tl.col = "black", tl.srt = 90,
         diag=FALSE, mar=c(0,0,0.1,0), tl.cex=0.4)
```

Column {data-width=350}
-----------------------------------------------------------------------

### Tablica korelacija

```{r}
datatable(korelacije_Finland, filter = 'top',
    extensions = c('FixedColumns','Select', 'Buttons'),
    options = list(
      dom = 'Blfrtip',
      select = list(style = 'os', items = 'row'),
      buttons = c('selectAll', 'selectNone', 'selectRows', 'selectColumns', 'selectCells'),
      pageLength = 15,
      scrollX = TRUE,
      fixedColumns = TRUE
    )
)
```

korelacije - Portugal
=======================================================================

Column {data-width=450}
-----------------------------------------------------------------------

### grafički prikaz korelacija

```{r}
corrplot(korelacije_Portugal, type = "upper", tl.col = "black", tl.srt = 90,
         diag=FALSE, mar=c(0,0,0.1,0), tl.cex=0.4)
```

Column {data-width=350}
-----------------------------------------------------------------------

### Tablica korelacija

```{r}
datatable(korelacije_Portugal, filter = 'top',
    extensions = c('FixedColumns','Select', 'Buttons'),
    options = list(
      dom = 'Blfrtip',
      select = list(style = 'os', items = 'row'),
      buttons = c('selectAll', 'selectNone', 'selectRows', 'selectColumns', 'selectCells'),
      pageLength = 15,
      scrollX = TRUE,
      fixedColumns = TRUE
    )
)
```

korelacije - Španjolska
=======================================================================

Column {data-width=450}
-----------------------------------------------------------------------

### grafički prikaz korelacija

```{r}
corrplot(korelacije_Spain, type = "upper", tl.col = "black", tl.srt = 90,
         diag=FALSE, mar=c(0,0,0.1,0), tl.cex=0.4)
```

Column {data-width=350}
-----------------------------------------------------------------------

### Tablica korelacija

```{r}
datatable(korelacije_Spain, filter = 'top',
    extensions = c('FixedColumns','Select', 'Buttons'),
    options = list(
      dom = 'Blfrtip',
      select = list(style = 'os', items = 'row'),
      buttons = c('selectAll', 'selectNone', 'selectRows', 'selectColumns', 'selectCells'),
      pageLength = 15,
      scrollX = TRUE,
      fixedColumns = TRUE
    )
)
```


