/
crosstalk_4.Rmd
executable file
·117 lines (103 loc) · 2.83 KB
/
crosstalk_4.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
---
title: "Crosstalk File 4"
author: "ADJ: Interactive Maps"
date: "9/26/2022"
output:
flexdashboard::flex_dashboard:
theme: paper
source_code: embed
---
```{r setup, include=FALSE}
# setting up R Markdown options
# We want to hide the code and only see the results
knitr::opts_chunk$set(echo = F)
# We don't want to see any warnings from our code
knitr::opts_chunk$set(warning = F)
# We don't want to see any messages
knitr::opts_chunk$set(message = F)
```
```{r install_packages}
# You must have the flexdashboard package installed
# Before knitting this R Markdown file
# install.packages("flexdashboard")
# This function checks if you don't have the correct packages installed yet
# If not, it will install it for you
packages <- c("tidyverse", "flexdashboard",
"crosstalk", "leaflet", "DT")
if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packages, rownames(installed.packages())), repos = "http://cran.us.r-project.org")
}
library(tidyverse)
library(flexdashboard)
library(crosstalk)
library(leaflet)
library(DT)
```
```{r load_and_clean_data}
# This example focuses on Louisiana
# Come back to this later if you want
# to change the state we're visualizing
# NOTE: You'll need to change the starting
# latitude and longitude of the map code below
state <- read_csv("data/all_pharmacies_summarized.csv") %>%
filter(BUYER_STATE=="LA") %>%
select(-BUYER_ADDL_CO_INFO, -BUYER_ADDRESS2) %>%
arrange(desc(per_person))
st <- SharedData$new(state)
```
Opioids in State {data-icon="ion-stats-bars"}
=====================================
Column {data-width=200}
-------------------------------------
### Filters
```{r filter_section}
filter_select(
id = "BUYER_COUNTY",
label = "County",
sharedData = st,
group = ~BUYER_COUNTY
)
bscols(
filter_checkbox(
id = "BUYER_BUS_ACT",
label = "Pharmacy type",
sharedData = st,
group = ~BUYER_BUS_ACT
)
)
bscols(
filter_slider(
id = "per_person",
label = "Pills per resident",
sharedData = st,
column = ~per_person,
step = 10,
round = TRUE,
sep = "",
ticks = FALSE
)
)
```
Column {data-width=800}
-------------------------------------
### Datatable
```{r filterable_table}
datatable(st)
```
### Interactive map
```{r interactive_map}
st %>%
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
setView(-92.469698, 31.012156, zoom = 7) %>%
addCircles(
popup = ~paste0("<strong>", state$BUYER_NAME ,"</strong><br />",
state$BUYER_CITY, "<br />",
state$per_person, " average pills per person<br />
<img src='http://www.andrewbatran.com/nicar/la_minicharts/plot_",
state$BUYER_DEA_NO, ".png' width=200px height=150px/>"),
radius=state$per_person*500,
stroke=FALSE,
opacity=.5
)
```