---
title: "Crosstalk"
output:
flexdashboard::flex_dashboard:
orientation: rows
source_code: embed
social: [ "twitter", "facebook", "menu" ]
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(tidyverse)
library(leaflet)
library(DT)
library(plotly)
library(crosstalk)
```
```{r data}
# load example data
df <- read_csv("example.csv")
# clean example data
df <-
df %>%
filter(!is.na(officer)) %>%
filter(status != "Not a Prospect") %>%
select(name, class, constituency, connection, status, priority, cap16, officer, latitude, longitude)
# Wrap data in SharedData to use with crosstalk
sd <- SharedData$new(df)
```
Inputs {.sidebar}
-------------------------------------
```{r filters}
# Filter input - Officer
filter_select(id = "officer",
label = "Select Gift Officer(s)",
sharedData = sd,
group = ~officer)
# Filter input - Status
filter_select(id = "status",
label = "Select Status",
sharedData = sd,
group = ~status)
# Filter checkbox - constituency
filter_checkbox(id = "cons",
label = "Constituency",
sharedData = sd,
group = ~constituency,
inline = TRUE)
# Filter slider - capital giving 2016
filter_slider(id = "giving",
label = "2016 Giving",
sharedData = sd,
column = ~cap16)
```
Row
-------------------------------------
### Map
```{r map}
sd %>%
leaflet() %>%
addProviderTiles("CartoDB") %>%
setView(lat = 39.8282, lng = -98.5795, zoom = 4) %>%
addCircleMarkers(radius = 2, popup = ~name)
```
### Chart
```{r plot}
plot_ly(sd, x = ~status) %>% add_histogram()
```
Row
-------------------------------------
### Table
```{r table}
datatable(sd, extensions= c('Buttons', "Scroller"),
class="compact", width="100%", rownames = FALSE,
options=list(
dom = 'Blfrtip',
deferRender=TRUE,
scrollY=300,
scroller=TRUE,
columnDefs = list(list(visible=FALSE, targets=c(8, 9))),
buttons = list(I('colvis'), 'csv', 'excel'))) %>%
formatCurrency('cap16', digits = 0)
```