0. ๋ฐ์ดํฐ
1. Flexdashboard ์ฐธ๊ณ ์๋ฃ
1-1. Flexdashboard ์์
2. leaflet ์ฐธ๊ณ ์๋ฃ
3. ๋์๋ณด๋ UI ์ฐธ๊ณ ์๋ฃ
4. ์๊ฒฝ๋๋ก ํ์ ๊ตฌ์ญ ์ถ์ถ ์ฐธ๊ณ ์๋ฃ
5. ์์ด์ฝ List
---
title: "Corona19 DashBoard"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
social: menu
theme: cosmo
storyboard: true
thumbnails: true
source: embed
logo: Gareth_Frank_Bale_circle.png
favicon: Gareth_Frank_Bale_circle.png
navbar:
- { icon: "fa-facebook-f", href: "https://www.facebook.com/shjj08", align: right }
- { icon: "fa-github", href: "https://github.com/Unfinishedgod", align: right }
---
```{r setup, include=FALSE}
library(flexdashboard)
library(readr)
library(tidyverse)
library(leaflet)
library(DT)
library(httr)
library(jsonlite)
library(plotly)
library(glue)
```
```{r}
corona_haspital <- read_csv("corona_haspital.csv",locale=locale('ko',encoding='euc-kr'))
corona_clinic <- read_csv("corona_clinic.csv",locale=locale('ko',encoding='euc-kr'))
# ์ง๋ฆฌ์ ๋ณด API๋ฅผ ์ฌ์ฉํ ์๊ฒฝ๋ ์ถ์ถ
Lat_lon_fun <- function(addr) {
data_list <-
GET(url = 'https://dapi.kakao.com/v2/local/search/address.json',
query = list(query = addr),
add_headers(Authorization = paste0("KakaoAK ", "2ecacbafd523802f293b245103346b06"))) %>%
content(as = 'text') %>%
fromJSON()
lon_lat_df <- tibble(์ฃผ์ = addr,
long = as.numeric(data_list$documents$x),
lat = as.numeric(data_list$documents$y))
return(lon_lat_df)
}
# ๋ณ์ ------------------------
hos_location_list <- corona_haspital$์ฃผ์
not_hos_list <- c(2,30,39,102,168,227,280)
hos_location_long_lat <- map_dfr(hos_location_list[-not_hos_list], function(x) {
Lat_lon_fun(x)
})
hos_info <- corona_haspital %>%
left_join(hos_location_long_lat) %>%
# select(์๋, ์๊ตฐ๊ตฌ, ๊ธฐ๊ด๋ช
, ์ฃผ์, ์ ํ๋ฒํธ, long, lat) %>%
rename(์ ํ = ์ ์ฒญ์ ํ)
# ์ง๋ฃ์ ------------------------
cli_location_list <- corona_clinic$์ฃผ์
not_cli_list <- c(128,131,158, 321,419,484, 538,540, 612)
cli_location_long_lat <- map_dfr(cli_location_list[-not_cli_list], function(x) {
Lat_lon_fun(x)
})
cli_info <- corona_clinic %>%
left_join(cli_location_long_lat) %>%
# select(์๋, ์๊ตฐ๊ตฌ, ์๋ฃ๊ธฐ๊ด๋ช
, ์ฃผ์, `๋ํ ์ ํ๋ฒํธ`, long, lat) %>%
rename(์ ํ๋ฒํธ = `๋ํ ์ ํ๋ฒํธ`, ๊ธฐ๊ด๋ช
= ์๋ฃ๊ธฐ๊ด๋ช
, ์ ํ = `๊ฒ์ฒด์ฑ์ทจ ๊ฐ๋ฅ์ฌ๋ถ`)
cli_info$์ ํ <- case_when(
cli_info$์ ํ == "Y" ~ "๊ฒ์ฒด์ฒด์ทจ ๊ฐ๋ฅ",
TRUE ~ "๊ฒ์ฒด์ฒด์ทจ ๋ถ๊ฐ"
)
hos_cli_info <- hos_info %>%
mutate(๊ตฌ๋ถ = "๊ตญ๋ฏผ์์ฌ๋ณ์") %>%
bind_rows((cli_info %>%
mutate(๊ตฌ๋ถ = "์ ๋ณ์ง๋ฃ์"))) %>%
drop_na(long) %>%
replace_na(list(์ด์๊ฐ๋ฅ์ผ์ = "์ด์๊ฐ๋ฅ")) %>%
select(๊ตฌ๋ถ, ์๋, ์๊ตฐ๊ตฌ, ๊ธฐ๊ด๋ช
, ์ฃผ์, ์ ํ, ์ ํ๋ฒํธ, ์ด์๊ฐ๋ฅ์ผ์, long, lat)
# write.csv(hos_cli_info, file = "hos_cli_info.csv")
# hos_cli_info <- read_csv("hos_cli_info.csv")
# hos_cli_info
hos_cli_info_seoul <- hos_cli_info %>%
filter(์๋ == "์์ธ")
hos_cli_info_daegu <- hos_cli_info %>%
filter(์๋ == "๋๊ตฌ")
```
์ ๊ตญ {data-navmenu="๋ณด๊ฑด๋ณต์ง๋ถ ์์ฌ๋ณ์๊ณผ ์ง๋ฃ์"}
=======================================================================
columns 1 {data-width=40%}
-----------------------------------------------------------------------
### ์ ๊ตญ ์์ฌ๋ณ์&์ง๋ฃ์ ์์น์ง๋
```{r}
# ๋ณด๊ฑด๋ณต์ง๋ถ ์์ฌ๋ณ์&์ง๋ฃ์
hos_cli_leaflet <- hos_cli_info %>%
mutate(ratingcol = case_when(
๊ตฌ๋ถ == "๊ตญ๋ฏผ์์ฌ๋ณ์" ~ "green",
TRUE ~ "blue"
))
leaflet() %>%
addTiles() %>%
addCircleMarkers(hos_cli_leaflet$long,
hos_cli_leaflet$lat,
color = hos_cli_leaflet$ratingcol,
radius = 8,
fill = T,
fillOpacity = 0.5,
opacity = 0.1,
popup = paste0(hos_cli_leaflet$๊ธฐ๊ด๋ช
, " \n(", hos_cli_leaflet$์ ํ๋ฒํธ,")")) %>%
addLegend("topright",
colors = c("green","blue"),
labels = c("๋ณด๊ฑด๋ณต์ง๋ถ ๊ตญ๋ฏผ์์ฌ๋ณ์",
"๋ณด๊ฑด๋ณต์ง๋ถ ์ ๋ณ์ง๋ฃ์"),
opacity = 1)
```
columns 2 { data-width=60%, data-height=200}
-------------------------------------
### ์๋๋ณ ์์ฌ๋ณ์ & ์ง๋ฃ์ ๊ทธ๋ํ {data-height=40%}
```{r}
theme_set(theme_classic())
# hos_cli_info$๊ตฌ๋ถ <- as.factor(hos_cli_info$๊ตฌ๋ถ)
#
# p <- hos_cli_info %>%
# group_by(๊ตฌ๋ถ,์๋) %>%
# summarise(๊ฐ์ = n()) %>%
# arrange(๊ตฌ๋ถ, ์๋) %>%
# ggplot(aes(x = ์๋, y = ๊ฐ์, fill = ๊ตฌ๋ถ)) +
# geom_col(position="dodge") +
# scale_fill_manual(values = c("green3", "blue3")) +
# labs(title = "์ง์ญ๋ณ ๋ณ์, ์ง๋ฃ์ ํ์
", x = "", y = "") +
# theme(legend.position = "bottom")
#
#
# ggplotly(p)
df_plotly <- hos_cli_info %>%
group_by(๊ตฌ๋ถ,์๋) %>%
summarise(๊ฐ์ = n()) %>%
arrange(๊ตฌ๋ถ, ์๋) %>%
spread(key = "๊ตฌ๋ถ", value = "๊ฐ์") %>%
replace_na(list(๊ตญ๋ฏผ์์ฌ๋ณ์ = 0))
m <- list(
l = 50,
r = 50,
b = 100,
t = 100,
pad = 4
)
df_plotly %>%
plot_ly(
x = ~์๋,
y = ~๊ตญ๋ฏผ์์ฌ๋ณ์,
type = "bar",
name = "๋ณด๊ฑด๋ณต์ง๋ถ ๊ตญ๋ฏผ์์ฌ๋ณ์",
textposition = 'auto',
marker = list(color = 'green')
) %>%
add_trace(y = ~์ ๋ณ์ง๋ฃ์,
name = "๋ณด๊ฑด๋ณต์ง๋ถ ์ ๋ณ์ง๋ฃ์",
textposition = 'auto',
marker = list(color = 'blue')) %>%
layout(legend = list(orientation = "v", # show entries horizontally
xanchor = "center", # use center of legend as anchor
x = 0.9,
y = 1.09,
autosize = F, width = 200, height = 100, margin = m))
```
### ๋ฐ์ดํฐ(์ ๊ตญ) {data-height=60%}
```{r}
hos_cli_info %>%
select(๊ตฌ๋ถ, ์๋, ์๊ตฐ๊ตฌ, ๊ธฐ๊ด๋ช
, ์ฃผ์, ์ ํ, ์ ํ๋ฒํธ, ์ด์๊ฐ๋ฅ์ผ์) %>%
datatable(rownames = FALSE)
```
์์ธ {data-navmenu="๋ณด๊ฑด๋ณต์ง๋ถ ์์ฌ๋ณ์๊ณผ ์ง๋ฃ์"}
=======================================================================
columns 1 {data-width=40%}
-----------------------------------------------------------------------
### ์์ธ - ์์ฌ๋ณ์&์ง๋ฃ์ ์์น์ง๋
```{r}
# ๋ณด๊ฑด๋ณต์ง๋ถ ์์ฌ๋ณ์&์ง๋ฃ์
hos_cli_leaflet <- hos_cli_info_seoul %>%
mutate(ratingcol = case_when(
๊ตฌ๋ถ == "๊ตญ๋ฏผ์์ฌ๋ณ์" ~ "green",
TRUE ~ "blue"
))
leaflet() %>%
addTiles() %>%
addCircleMarkers(hos_cli_leaflet$long,
hos_cli_leaflet$lat,
color = hos_cli_leaflet$ratingcol,
radius = 8,
fill = T,
fillOpacity = 0.5,
opacity = 0.1,
popup = paste0(hos_cli_leaflet$๊ธฐ๊ด๋ช
, " \n(", hos_cli_leaflet$์ ํ๋ฒํธ,")")) %>%
addLegend("topright",
colors = c("green","blue"),
labels = c("๋ณด๊ฑด๋ณต์ง๋ถ ๊ตญ๋ฏผ์์ฌ๋ณ์",
"๋ณด๊ฑด๋ณต์ง๋ถ ์ ๋ณ์ง๋ฃ์"),
opacity = 1)
```
columns 2 { data-width=60%, data-height=200}
-------------------------------------
### ์์ธ - ๊ตฌ๋ณ ์์ฌ๋ณ์ & ์ง๋ฃ์ ๊ทธ๋ํ {data-height=40%}
```{r}
theme_set(theme_classic())
# hos_cli_info$๊ตฌ๋ถ <- as.factor(hos_cli_info$๊ตฌ๋ถ)
#
# p <- hos_cli_info %>%
# group_by(๊ตฌ๋ถ,์๋) %>%
# summarise(๊ฐ์ = n()) %>%
# arrange(๊ตฌ๋ถ, ์๋) %>%
# ggplot(aes(x = ์๋, y = ๊ฐ์, fill = ๊ตฌ๋ถ)) +
# geom_col(position="dodge") +
# scale_fill_manual(values = c("green3", "blue3")) +
# labs(title = "์ง์ญ๋ณ ๋ณ์, ์ง๋ฃ์ ํ์
", x = "", y = "") +
# theme(legend.position = "bottom")
#
#
# ggplotly(p)
df_plotly <- hos_cli_info_seoul %>%
group_by(๊ตฌ๋ถ,์๊ตฐ๊ตฌ) %>%
summarise(๊ฐ์ = n()) %>%
arrange(๊ตฌ๋ถ, ์๊ตฐ๊ตฌ) %>%
spread(key = "๊ตฌ๋ถ", value = "๊ฐ์") %>%
replace_na(list(๊ตญ๋ฏผ์์ฌ๋ณ์ = 0))
m <- list(
l = 50,
r = 50,
b = 100,
t = 100,
pad = 4
)
df_plotly %>%
plot_ly(
x = ~์๊ตฐ๊ตฌ,
y = ~๊ตญ๋ฏผ์์ฌ๋ณ์,
type = "bar",
name = "๋ณด๊ฑด๋ณต์ง๋ถ ๊ตญ๋ฏผ์์ฌ๋ณ์",
textposition = 'auto',
marker = list(color = 'green')
) %>%
add_trace(y = ~์ ๋ณ์ง๋ฃ์,
name = "๋ณด๊ฑด๋ณต์ง๋ถ ์ ๋ณ์ง๋ฃ์",
textposition = 'auto',
marker = list(color = 'blue')) %>%
layout(legend = list(orientation = "v", # show entries horizontally
xanchor = "center", # use center of legend as anchor
x = 0.9,
y = 1.09,
autosize = F, width = 200, height = 100, margin = m))
```
### ๋ฐ์ดํฐ(์์ธ) {data-height=60%}
```{r}
hos_cli_info_seoul %>%
select(๊ตฌ๋ถ, ์๊ตฐ๊ตฌ, ๊ธฐ๊ด๋ช
, ์ฃผ์, ์ ํ, ์ ํ๋ฒํธ, ์ด์๊ฐ๋ฅ์ผ์) %>%
datatable(rownames = FALSE)
```
๋๊ตฌ {data-navmenu="๋ณด๊ฑด๋ณต์ง๋ถ ์์ฌ๋ณ์๊ณผ ์ง๋ฃ์"}
=======================================================================
columns 1 {data-width=40%}
-----------------------------------------------------------------------
### ๋๊ตฌ - ์์ฌ๋ณ์&์ง๋ฃ์ ์์น์ง๋
```{r}
# ๋ณด๊ฑด๋ณต์ง๋ถ ์์ฌ๋ณ์&์ง๋ฃ์
hos_cli_leaflet <- hos_cli_info_daegu %>%
mutate(ratingcol = case_when(
๊ตฌ๋ถ == "๊ตญ๋ฏผ์์ฌ๋ณ์" ~ "green",
TRUE ~ "blue"
))
leaflet() %>%
addTiles() %>%
addCircleMarkers(hos_cli_leaflet$long,
hos_cli_leaflet$lat,
color = hos_cli_leaflet$ratingcol,
radius = 8,
fill = T,
fillOpacity = 0.5,
opacity = 0.1,
popup = paste0(hos_cli_leaflet$๊ธฐ๊ด๋ช
, " \n(", hos_cli_leaflet$์ ํ๋ฒํธ,")")) %>%
addLegend("topright",
colors = c("green","blue"),
labels = c("๋ณด๊ฑด๋ณต์ง๋ถ ๊ตญ๋ฏผ์์ฌ๋ณ์",
"๋ณด๊ฑด๋ณต์ง๋ถ ์ ๋ณ์ง๋ฃ์"),
opacity = 1)
```
columns 2 { data-width=60%, data-height=200}
-------------------------------------
### ๋๊ตฌ - ๊ตฌ๋ณ ์์ฌ๋ณ์ & ์ง๋ฃ์ ๊ทธ๋ํ {data-height=40%}
```{r}
theme_set(theme_classic())
# hos_cli_info$๊ตฌ๋ถ <- as.factor(hos_cli_info$๊ตฌ๋ถ)
#
# p <- hos_cli_info %>%
# group_by(๊ตฌ๋ถ,์๋) %>%
# summarise(๊ฐ์ = n()) %>%
# arrange(๊ตฌ๋ถ, ์๋) %>%
# ggplot(aes(x = ์๋, y = ๊ฐ์, fill = ๊ตฌ๋ถ)) +
# geom_col(position="dodge") +
# scale_fill_manual(values = c("green3", "blue3")) +
# labs(title = "์ง์ญ๋ณ ๋ณ์, ์ง๋ฃ์ ํ์
", x = "", y = "") +
# theme(legend.position = "bottom")
#
#
# ggplotly(p)
df_plotly <- hos_cli_info_daegu %>%
group_by(๊ตฌ๋ถ,์๊ตฐ๊ตฌ) %>%
summarise(๊ฐ์ = n()) %>%
arrange(๊ตฌ๋ถ, ์๊ตฐ๊ตฌ) %>%
spread(key = "๊ตฌ๋ถ", value = "๊ฐ์") %>%
replace_na(list(๊ตญ๋ฏผ์์ฌ๋ณ์ = 0))
m <- list(
l = 50,
r = 50,
b = 100,
t = 100,
pad = 4
)
df_plotly %>%
plot_ly(
x = ~์๊ตฐ๊ตฌ,
y = ~๊ตญ๋ฏผ์์ฌ๋ณ์,
type = "bar",
name = "๋ณด๊ฑด๋ณต์ง๋ถ ๊ตญ๋ฏผ์์ฌ๋ณ์",
textposition = 'auto',
marker = list(color = 'green')
) %>%
add_trace(y = ~์ ๋ณ์ง๋ฃ์,
name = "๋ณด๊ฑด๋ณต์ง๋ถ ์ ๋ณ์ง๋ฃ์",
textposition = 'auto',
marker = list(color = 'blue')) %>%
layout(legend = list(orientation = "v", # show entries horizontally
xanchor = "center", # use center of legend as anchor
x = 0.9,
y = 1.09,
autosize = F, width = 200, height = 100, margin = m))
```
### ๋ฐ์ดํฐ(๋๊ตฌ) {data-height=60%}
```{r}
hos_cli_info_daegu %>%
select(๊ตฌ๋ถ, ์๊ตฐ๊ตฌ, ๊ธฐ๊ด๋ช
, ์ฃผ์, ์ ํ, ์ ํ๋ฒํธ, ์ด์๊ฐ๋ฅ์ผ์) %>%
datatable(rownames = FALSE)
```
์ ๊ตญ {data-navmenu="๋ง์คํฌ ์ ๊ณต ์ ๋ณด"}
=======================================================================
```{r}
# ๋ง์คํฌ ์ ๋ณด API ------------------------
# 1. ์ฃผ์/์ขํ ๊ธฐ์ค ํ๋งค์ฒ๋ณ ๊ณต์ ๋ง์คํฌ ํ๋งค์ ๋ณด ์ ๊ณต ์๋น์ค
url_1 <- "https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/stores/json?page=1&perPage=5000"
# 2. ํ๋งค์ฒ๋ณ ๊ณต์ ๋ง์คํฌ ํ๋งค์ฒ ์ ๋ณด ์ ๊ณต ์๋น์ค
url_2 <- "https://8oi9s0nnth.apigw.ntruss.com/corona19-masks/v1/sales/json?page=1&perPage=5000"
file_1 <- fromJSON(url_1)
file_2 <- fromJSON(url_2)
# 1๋ฒ
df_1 <- file_1$storeInfos %>%
as_tibble()
# 2๋ฒ
df_2 <- file_2$sales %>%
as_tibble()
asdf <- df_1 %>%
left_join(df_2) %>%
# replace_na(list(created_at = "์ ๋ณด ์์", remain_stat = "์ ๋ณด์์", stock_at = "์ ๋ณด ์์")) %>%
drop_na() %>%
mutate(remain_stat_kr = case_when(
remain_stat == "plenty" ~ "100๊ฐ ์ด์",
remain_stat == "some" ~ "30๊ฐ ์ด์ 100๊ฐ ๋ฏธ๋ง",
remain_stat == "few" ~ "2๊ฐ ์ด์ 30๊ฐ ๋ฏธ๋ง",
remain_stat == "empty" ~ "1๊ฐ ์ดํ",
remain_stat == "break" ~ "2๊ฐ ์ด์ 30๊ฐ ๋ฏธ๋ง",
TRUE ~ "์ ๋ณด ์์"
), ๊ตฌ๋ถ = case_when(
type == "01" ~ "์ฝ๊ตญ",
type == "02" ~ "์ฐ์ฒด๊ตญ",
TRUE ~ "๋ํ"
))
lng_lat_list <- map_chr(1:nrow(asdf), function(x) {
glue("x={asdf[x,4]}&y={asdf[x,3]}")
})
# ์๊ฒฝ๋๋ฅผ ์ฌ์ฉํ ์ง๋ฆฌ์ ๋ณด ์ถ์ถ
addr_fun <- function(lng_lat) {
data_list <- GET(url = glue("https://dapi.kakao.com/v2/local/geo/coord2regioncode.json?{lng_lat}"),
# query = list(query = addr),
add_headers(Authorization = paste0("KakaoAK ", "2ecacbafd523802f293b245103346b06"))) %>%
content(as = 'text') %>%
fromJSON()
lng_processing <- lng_lat %>%
str_split("&")
raw_lng <- lng_processing[[1]][1] %>%
str_sub(3,max(nchar(lng_processing[[1]][1]))) %>%
as.numeric()
addr_df <- tibble(
# lng = data_list$documents$x[1],
lng = raw_lng,
์๋ = data_list$documents$region_1depth_name[1],
์๊ตฐ๊ตฌ = data_list$documents$region_2depth_name[1],
๋ = data_list$documents$region_3depth_name[1])
return(addr_df)
}
addr_info <- map_dfr(lng_lat_list , function(x) {
addr_fun(x)
})
asdf_2 <- asdf %>%
left_join(addr_info)
#
#
# write.csv(asdf_2, file = "mask_df.csv")
# asdf_2 <- read_csv("mask_df.csv")
asdf <- asdf_2
asdf_seoul <- asdf_2 %>%
filter(์๋ == "์์ธํน๋ณ์")
asdf_daegu <- asdf_2 %>%
filter(์๋ == "๋๊ตฌ๊ด์ญ์")
```
Colunms 1 {data-width=40%}
-----------------------------------------------------------------------
### ์ ๊ตญ ๋ง์คํฌ ์ ๊ณต ์์น์ง๋
```{r}
# ๋ง์คํฌ ํ๋งค์ฒ leaflet ------------------------
asdf_leaflet <- asdf %>%
mutate(ratingcol = case_when(
type == "01" & remain_stat != "์ ๋ณด์์" ~ "green",
type == "02" & remain_stat != "์ ๋ณด์์"~ "orange",
type == "03" & remain_stat != "์ ๋ณด์์"~ "blue",
TRUE ~ "black"
))
leaflet() %>%
addTiles() %>%
addCircleMarkers(asdf_leaflet$lng,
asdf_leaflet$lat,
color = asdf_leaflet$ratingcol,
radius = 8,
fill = T,
fillOpacity = 0.6,
opacity = 0.1,
popup = paste0(asdf_leaflet$name," (",asdf_leaflet$addr, "(",asdf_leaflet$remain_stat_kr,"))")) %>%
addLegend("topright",
colors = c("green","orange","blue"),
labels = c("์ฝ๊ตญ",
"์ฐ์ฒด๊ตญ",
"๋ํ"),
opacity = 1)
```
Colunms 2 { data-width=60%, data-height=200}
-----------------------------------------------------------------------
### ์๋๋ณ ๋ง์คํฌ ์ ๊ณต ๊ธฐ๊ด ๊ทธ๋ํ {data-height=40%}
```{r}
df_plotly <- asdf_2 %>%
group_by(๊ตฌ๋ถ,์๋) %>%
summarise(๊ฐ์ = n()) %>%
arrange(๊ตฌ๋ถ, ์๋) %>%
spread(key = "๊ตฌ๋ถ", value = "๊ฐ์") %>%
replace_na(list(๋ํ = 0, ์ฝ๊ตญ = 0, ์ฐ์ฒด๊ตญ=0))
df_plotly %>%
plot_ly(
x = ~์๋,
y = ~์ฝ๊ตญ,
type = "bar",
name = "์ฝ๊ตญ",
textposition = 'auto',
marker = list(color = 'green')
) %>%
add_trace(y = ~์ฐ์ฒด๊ตญ,
name = "์ฐ์ฒด๊ตญ",
textposition = 'auto',
marker = list(color = 'orange')) %>%
add_trace(y = ~๋ํ,
name = "๋ํ",
textposition = 'auto',
marker = list(color = 'blue')) %>%
layout(legend = list(orientation = "v", # show entries horizontally
xanchor = "center", # use center of legend as anchor
x = 0.9,
y = 1.09))
```
### ๋ฐ์ดํฐ(์ ๊ตญ) {data-height=60%}
```{r}
asdf_2 %>%
select(๊ตฌ๋ถ, ์๋, ์๊ตฐ๊ตฌ, name,addr, created_at, stock_at, remain_stat_kr) %>%
rename(๊ธฐ๊ด๋ช
= name, ์ฃผ์ = addr, ์
๊ณ ์ผ์ = stock_at, ์์ฑ์ผ์ = created_at, ์ฌ๊ณ ์ ๋ณด = remain_stat_kr) %>%
datatable(rownames = FALSE)
```
์์ธ {data-navmenu="๋ง์คํฌ ์ ๊ณต ์ ๋ณด"}
=======================================================================
columns 1 {data-width=40%}
-----------------------------------------------------------------------
### ์์ธ ๋ง์คํฌ ์ ๊ณต ์์น์ง๋
```{r}
# ๋ง์คํฌ ํ๋งค์ฒ leaflet ------------------------
asdf_leaflet <- asdf_seoul %>%
mutate(ratingcol = case_when(
type == "01" & remain_stat != "์ ๋ณด์์" ~ "green",
type == "02" & remain_stat != "์ ๋ณด์์"~ "orange",
type == "03" & remain_stat != "์ ๋ณด์์"~ "blue",
TRUE ~ "black"
))
leaflet() %>%
addTiles() %>%
addCircleMarkers(asdf_leaflet$lng,
asdf_leaflet$lat,
color = asdf_leaflet$ratingcol,
radius = 8,
fill = T,
fillOpacity = 0.6,
opacity = 0.1,
popup = paste0(asdf_leaflet$name," (",asdf_leaflet$addr, "(",asdf_leaflet$remain_stat_kr,"))")) %>%
addLegend("topright",
colors = c("green","orange","blue"),
labels = c("์ฝ๊ตญ",
"์ฐ์ฒด๊ตญ",
"๋ํ"),
opacity = 1)
```
columns 2 { data-width=60%, data-height=200}
-------------------------------------
### ์์ธ ๊ตฌ๋ณ ๋ง์คํฌ ์ ๊ณต ๊ธฐ๊ด ๊ทธ๋ํ {data-height=40%}
```{r}
df_plotly <- asdf_seoul %>%
group_by(๊ตฌ๋ถ,์๊ตฐ๊ตฌ) %>%
summarise(๊ฐ์ = n()) %>%
arrange(๊ตฌ๋ถ, ์๊ตฐ๊ตฌ) %>%
spread(key = "๊ตฌ๋ถ", value = "๊ฐ์") %>%
replace_na(list(๋ํ = 0, ์ฝ๊ตญ = 0, ์ฐ์ฒด๊ตญ=0))
df_plotly <- df_plotly %>%
mutate("๋ํ" = 0,
"์ฐ์ฒด๊ตญ" = 0)
df_plotly %>%
plot_ly(
x = ~์๊ตฐ๊ตฌ,
y = ~์ฝ๊ตญ,
type = "bar",
name = "์ฝ๊ตญ",
textposition = 'auto',
marker = list(color = 'green')
) %>%
add_trace(y = ~์ฐ์ฒด๊ตญ,
name = "์ฐ์ฒด๊ตญ",
textposition = 'auto',
marker = list(color = 'orange')) %>%
add_trace(y = ~๋ํ,
name = "๋ํ",
textposition = 'auto',
marker = list(color = 'blue')) %>%
layout(legend = list(orientation = "v", # show entries horizontally
xanchor = "center", # use center of legend as anchor
x = 0.9,
y = 1.09))
```
### ๋ฐ์ดํฐ(์์ธ) {data-height=60%}
```{r}
asdf_seoul %>%
select(๊ตฌ๋ถ, ์๋, ์๊ตฐ๊ตฌ, name,addr, created_at, stock_at, remain_stat_kr) %>%
rename(๊ธฐ๊ด๋ช
= name, ์ฃผ์ = addr, ์
๊ณ ์ผ์ = stock_at, ์์ฑ์ผ์ = created_at, ์ฌ๊ณ ์ ๋ณด = remain_stat_kr) %>%
datatable(rownames = FALSE)
```
๋๊ตฌ {data-navmenu="๋ง์คํฌ ์ ๊ณต ์ ๋ณด"}
=======================================================================
columns 1 {data-width=40%}
-----------------------------------------------------------------------
### ๋๊ตฌ ๋ง์คํฌ ์ ๊ณต ์์น์ง๋
```{r}
# ๋ง์คํฌ ํ๋งค์ฒ leaflet ------------------------
asdf_leaflet <- asdf_daegu %>%
mutate(ratingcol = case_when(
type == "01" & remain_stat != "์ ๋ณด์์" ~ "green",
type == "02" & remain_stat != "์ ๋ณด์์"~ "orange",
type == "03" & remain_stat != "์ ๋ณด์์"~ "blue",
TRUE ~ "black"
))
leaflet() %>%
addTiles() %>%
addCircleMarkers(asdf_leaflet$lng,
asdf_leaflet$lat,
color = asdf_leaflet$ratingcol,
radius = 8,
fill = T,
fillOpacity = 0.6,
opacity = 0.1,
popup = paste0(asdf_leaflet$name," (",asdf_leaflet$addr, "(",asdf_leaflet$remain_stat_kr,"))")) %>%
addLegend("topright",
colors = c("green","orange","blue"),
labels = c("์ฝ๊ตญ",
"์ฐ์ฒด๊ตญ",
"๋ํ"),
opacity = 1)
```
columns 2 { data-width=60%, data-height=200}
-------------------------------------
### ๋๊ตฌ ๊ตฌ๋ณ ๋ง์คํฌ ์ ๊ณต ๊ธฐ๊ด ๊ทธ๋ํ {data-height=40%}
```{r}
df_plotly <- asdf_daegu %>%
group_by(๊ตฌ๋ถ,์๊ตฐ๊ตฌ) %>%
summarise(๊ฐ์ = n()) %>%
arrange(๊ตฌ๋ถ, ์๊ตฐ๊ตฌ) %>%
spread(key = "๊ตฌ๋ถ", value = "๊ฐ์") %>%
replace_na(list(๋ํ = 0, ์ฝ๊ตญ = 0, ์ฐ์ฒด๊ตญ=0))
df_plotly <- df_plotly %>%
mutate("๋ํ" = 0)
df_plotly %>%
plot_ly(
x = ~์๊ตฐ๊ตฌ,
y = ~์ฝ๊ตญ,
type = "bar",
name = "์ฝ๊ตญ",
textposition = 'auto',
marker = list(color = 'green')
) %>%
add_trace(y = ~์ฐ์ฒด๊ตญ,
name = "์ฐ์ฒด๊ตญ",
textposition = 'auto',
marker = list(color = 'orange')) %>%
add_trace(y = ~๋ํ,
name = "๋ํ",
textposition = 'auto',
marker = list(color = 'blue')) %>%
layout(legend = list(orientation = "v", # show entries horizontally
xanchor = "center", # use center of legend as anchor
x = 0.9,
y = 1.09))
```
### ๋ฐ์ดํฐ(๋๊ตฌ) {data-height=60%}
```{r}
asdf_daegu %>%
select(๊ตฌ๋ถ, ์๋, ์๊ตฐ๊ตฌ, name,addr, created_at, stock_at, remain_stat_kr) %>%
rename(๊ธฐ๊ด๋ช
= name, ์ฃผ์ = addr, ์
๊ณ ์ผ์ = stock_at, ์์ฑ์ผ์ = created_at, ์ฌ๊ณ ์ ๋ณด = remain_stat_kr) %>%
datatable(rownames = FALSE)
```
Reference
=======================================================================
**0. ๋ฐ์ดํฐ **
- ๊ณต๊ณต๋ฐ์ดํฐ ํฌํธ - ์ฝ๋ก๋ : https://www.data.go.kr/issues/3/show.do
**1. Flexdashboard ์ฐธ๊ณ ์๋ฃ**
- Flexdashboard ํํ ๋ฆฌ์ผ: https://rmarkdown.rstudio.com/flexdashboard/index.html
- ํ
๋ง: http://www.sangerw.com/blog/flexdashboardthemes/#IDreadable
- Flexdashboard CRAN: https://cran.r-project.org/web/packages/flexdashboard/flexdashboard.pdf
- bookdown in Flexdashboard: https://bookdown.org/yihui/rmarkdown/dashboards.html
- Making Dashboards in R Markdown: https://arm.rbind.io/slides/flexdashboard.html
**1-1. Flexdashboard ์์ **
- ์์ 1: https://beta.rstudioconnect.com/juliasilge/policeshooting/policeshooting.html
- ์์ ์ฝ๋: https://gist.github.com/juliasilge/9acbe97c549502bac85404779edceba0
- ์์ 2: https://jenthompson.me/examples/progressdash.html
- ์์ ์ฝ๋: https://github.com/jenniferthompson/MOSAICProgress/blob/master/progressdash.Rmd
- ์์ 3: https://jenthompson.me/examples/insight_progress.html
- ์์ ์ฝ๋: https://github.com/jenniferthompson/INSIGHTProgress/blob/master/insight_progress.Rmd
- ์์ 4: https://tonyelhabr.rbind.io/files/nba-tms.html
**2. leaflet ์ฐธ๊ณ ์๋ฃ**
- https://rstudio.github.io/leaflet/
- https://leafletjs.com/examples.html
- https://rstudio.github.io/leaflet/
**3. ๋์๋ณด๋ UI ์ฐธ๊ณ ์๋ฃ**
- http://ncov.mohw.go.kr/
- http://www.bix5.net/examples
**4. ์๊ฒฝ๋๋ก ํ์ ๊ตฌ์ญ ์ถ์ถ ์ฐธ๊ณ ์๋ฃ**
- https://developers.kakao.com/docs/restapi/local#์ขํ-ํ์ ๊ตฌ์ญ์ ๋ณด-๋ณํ
**5. ์์ด์ฝ List**
- https://fontawesome.com/v4.7.0/icons/