SlideShare a Scribd company logo
1 of 33
Download to read offline
> me
$name
[1] "Takashi Kitano"
$twitter
[1] "@kashitan"
$work_in
[1] " " %>% " "




glimpse(choices)
List of 4
$ : Named chr [1:58] "11101" "11102" "11103" "11104" ...
..- attr(*, "names")= chr [1:58] " " " " "
" " " ...
$ : Named chr [1:36] "12101" "12102" "12103" "12104" ...
..- attr(*, "names")= chr [1:36] " " " " "
" " " ...
$ : Named chr [1:51] "13101" "13102" "13103" "13104" ...
..- attr(*, "names")= chr [1:51] " " " " " " "
" ...
names(choices)
[1] " " " " " " " "
choices[[" "]]
"13101" "13102" "13103" "13104" "13105" "13106"
"13107" "13108" "13109"
"13110" "13111" "13112" "13113" "13114" "13115"
"13116" "13117" "13118"
selectInput(
inputId = "pref",
label = " ",
choices = names(choices),
selected = " ",
width = "100%"
)
selectInput(
inputId = "city",
label = " ",
#
choices = choices$` `,
selected = "13112",
width = "100%"
)
server <- function(input, output, session) {
observe({
city_choices <- choices[[input$pref]]
city <- input$city
#
#
if (!(city %in% city_choices)) {
city <- city_choices[1]
}
updateSelectInput(
session, inputId = “city",
choices = city_choices, selected = city
)
})
}
#
tags$style(type = "text/css", "#map {height: calc(90vh - 80px) !
important;}"),
leafletOutput("map")
output$map <- leaflet::renderLeaflet({
leaflet::leaflet() %>%
leaflet::addProviderTiles(providers$CartoDB.Positron)
})
observe({
pal <-
leaflet::colorNumeric("Spectral", dat.sub()$n, reverse = TRUE)
map <- leaflet::leafletProxy("map", data = dat.sub()) %>%
leaflet::clearShapes() %>%
leaflet::clearControls() %>%
leaflet::addPolygons(fillColor = ~ pal(n), color = "gray",
popup = ~ NAME, weight = 1,
fillOpacity = 0.8) %>%
leaflet::addLegend("bottomright", pal = pal, values = ~ n,
title = "Population", opacity = 1)
map
})
observe({
pal <-
leaflet::colorNumeric("Spectral", dat.sub()$n, reverse = TRUE)
map <- leaflet::leafletProxy("map", data = dat.sub()) %>%
leaflet::clearShapes() %>%
leaflet::clearControls() %>%
leaflet::addPolygons(fillColor = ~ pal(n), color = "gray",
popup = ~ NAME, weight = 1,
fillOpacity = 0.8) %>%
leaflet::addLegend("bottomright", pal = pal, values = ~ n,
title = "Population", opacity = 1)
map
})
is.fitBounds <- FALSE
observeEvent(input$city, {
is.fitBounds <<- TRUE
})
observe({
if (is.fitBounds) {
#
bbox <- dat.sub() %>%
sf::st_bbox()
names(bbox) <- NULL
map <- map %>%
leaflet::fitBounds(bbox[1], bbox[2], bbox[3], bbox[4])
is.fitBounds <<- FALSE
}
map
is.fitBounds <- FALSE
observeEvent(input$city, {
is.fitBounds <<- TRUE
})
observe({
if (is.fitBounds) {
#
bbox <- dat.sub() %>%
sf::st_bbox()
names(bbox) <- NULL
map <- map %>%
leaflet::fitBounds(bbox[1], bbox[2], bbox[3], bbox[4])
is.fitBounds <<- FALSE
}
map
observeEvent(input$map_shape_click, {
p <- input$map_shape_click
#
shp.sub <- shp[[input$pref]] %>%
dplyr::filter(stringr::str_sub(KEY_CODE, 1, 5) %in%
choices[[input$pref]])
#
ind <- sf::st_point(c(p$lng, p$lat), dim = "XY") %>%
sf::st_within(shp.sub) %>% unlist()
})
observeEvent(input$map_shape_click, {
p <- input$map_shape_click
#
shp.sub <- shp[[input$pref]] %>%
dplyr::filter(stringr::str_sub(KEY_CODE, 1, 5) %in%
choices[[input$pref]])
#
ind <- sf::st_point(c(p$lng, p$lat), dim = "XY") %>%
sf::st_within(shp.sub) %>% unlist()
})
{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips
{shiny}と{leaflet}による地図アプリ開発Tips

More Related Content

What's hot

Tokyor35 人工データの発生
Tokyor35 人工データの発生Tokyor35 人工データの発生
Tokyor35 人工データの発生
Yohei Sato
 
InfluxDB の概要 - sonots #tokyoinfluxdb
InfluxDB の概要 - sonots #tokyoinfluxdbInfluxDB の概要 - sonots #tokyoinfluxdb
InfluxDB の概要 - sonots #tokyoinfluxdb
Naotoshi Seo
 

What's hot (20)

実践で学ぶネットワーク分析
実践で学ぶネットワーク分析実践で学ぶネットワーク分析
実践で学ぶネットワーク分析
 
Tokyor35 人工データの発生
Tokyor35 人工データの発生Tokyor35 人工データの発生
Tokyor35 人工データの発生
 
星野「調査観察データの統計科学」第3章
星野「調査観察データの統計科学」第3章星野「調査観察データの統計科学」第3章
星野「調査観察データの統計科学」第3章
 
Prml2.1 2.2,2.4-2.5
Prml2.1 2.2,2.4-2.5Prml2.1 2.2,2.4-2.5
Prml2.1 2.2,2.4-2.5
 
Graphic Notes on Linear Algebra and Data Science
Graphic Notes on Linear Algebra and Data ScienceGraphic Notes on Linear Algebra and Data Science
Graphic Notes on Linear Algebra and Data Science
 
距離とクラスタリング
距離とクラスタリング距離とクラスタリング
距離とクラスタリング
 
データ解析6 重回帰分析
データ解析6 重回帰分析データ解析6 重回帰分析
データ解析6 重回帰分析
 
F#入門 ~関数プログラミングとは何か~
F#入門 ~関数プログラミングとは何か~F#入門 ~関数プログラミングとは何か~
F#入門 ~関数プログラミングとは何か~
 
R言語による簡便な有意差の検出と信頼区間の構成
R言語による簡便な有意差の検出と信頼区間の構成R言語による簡便な有意差の検出と信頼区間の構成
R言語による簡便な有意差の検出と信頼区間の構成
 
データサイエンス概論第一=2-2 クラスタリング
データサイエンス概論第一=2-2 クラスタリングデータサイエンス概論第一=2-2 クラスタリング
データサイエンス概論第一=2-2 クラスタリング
 
東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2
東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2
東京都市大学 データ解析入門 5 スパース性と圧縮センシング 2
 
データ解析8 主成分分析の応用
データ解析8 主成分分析の応用データ解析8 主成分分析の応用
データ解析8 主成分分析の応用
 
InfluxDB の概要 - sonots #tokyoinfluxdb
InfluxDB の概要 - sonots #tokyoinfluxdbInfluxDB の概要 - sonots #tokyoinfluxdb
InfluxDB の概要 - sonots #tokyoinfluxdb
 
学習時に使ってはいないデータの混入「リーケージを避ける」
学習時に使ってはいないデータの混入「リーケージを避ける」学習時に使ってはいないデータの混入「リーケージを避ける」
学習時に使ってはいないデータの混入「リーケージを避ける」
 
Rによるベイジアンネットワーク入門
Rによるベイジアンネットワーク入門Rによるベイジアンネットワーク入門
Rによるベイジアンネットワーク入門
 
はじめての「R」
はじめての「R」はじめての「R」
はじめての「R」
 
非劣性試験の入門
非劣性試験の入門非劣性試験の入門
非劣性試験の入門
 
機械学習は化学研究の"経験と勘"を合理化できるか?
機械学習は化学研究の"経験と勘"を合理化できるか?機械学習は化学研究の"経験と勘"を合理化できるか?
機械学習は化学研究の"経験と勘"を合理化できるか?
 
「plyrパッケージで君も前処理スタ☆」改め「plyrパッケージ徹底入門」
「plyrパッケージで君も前処理スタ☆」改め「plyrパッケージ徹底入門」「plyrパッケージで君も前処理スタ☆」改め「plyrパッケージ徹底入門」
「plyrパッケージで君も前処理スタ☆」改め「plyrパッケージ徹底入門」
 
大規模ネットワーク分析 篠田
大規模ネットワーク分析 篠田大規模ネットワーク分析 篠田
大規模ネットワーク分析 篠田
 

Similar to {shiny}と{leaflet}による地図アプリ開発Tips

JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
PROIDEA
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
riue
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
kesav24
 

Similar to {shiny}と{leaflet}による地図アプリ開発Tips (20)

JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
 
An example of R code for Data visualization
An example of R code for Data visualizationAn example of R code for Data visualization
An example of R code for Data visualization
 
[1062BPY12001] Data analysis with R / week 4
[1062BPY12001] Data analysis with R / week 4[1062BPY12001] Data analysis with R / week 4
[1062BPY12001] Data analysis with R / week 4
 
R lecture oga
R lecture ogaR lecture oga
R lecture oga
 
Map, Reduce and Filter in Swift
Map, Reduce and Filter in SwiftMap, Reduce and Filter in Swift
Map, Reduce and Filter in Swift
 
purrr.pdf
purrr.pdfpurrr.pdf
purrr.pdf
 
BOXPLOT EXAMPLES in R And An Example for BEESWARM:
BOXPLOT EXAMPLES in R And  An Example for BEESWARM:BOXPLOT EXAMPLES in R And  An Example for BEESWARM:
BOXPLOT EXAMPLES in R And An Example for BEESWARM:
 
Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collections
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
 
library(sparkline)
library(sparkline)library(sparkline)
library(sparkline)
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
Python Lecture 11
Python Lecture 11Python Lecture 11
Python Lecture 11
 
GenStage and Flow - Jose Valim
GenStage and Flow - Jose Valim GenStage and Flow - Jose Valim
GenStage and Flow - Jose Valim
 
Some Examples in R- [Data Visualization--R graphics]
 Some Examples in R- [Data Visualization--R graphics] Some Examples in R- [Data Visualization--R graphics]
Some Examples in R- [Data Visualization--R graphics]
 
Python Collection datatypes
Python Collection datatypesPython Collection datatypes
Python Collection datatypes
 
Zippers
ZippersZippers
Zippers
 
List out of lambda
List out of lambdaList out of lambda
List out of lambda
 
Артём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data AnalysisАртём Акуляков - F# for Data Analysis
Артём Акуляков - F# for Data Analysis
 

More from Takashi Kitano

好みの日本酒を呑みたい! 〜さけのわデータで探す自分好みの酒〜
好みの日本酒を呑みたい! 〜さけのわデータで探す自分好みの酒〜好みの日本酒を呑みたい! 〜さけのわデータで探す自分好みの酒〜
好みの日本酒を呑みたい! 〜さけのわデータで探す自分好みの酒〜
Takashi Kitano
 
Google's r style guideのすゝめ
Google's r style guideのすゝめGoogle's r style guideのすゝめ
Google's r style guideのすゝめ
Takashi Kitano
 

More from Takashi Kitano (13)

好みの日本酒を呑みたい! 〜さけのわデータで探す自分好みの酒〜
好みの日本酒を呑みたい! 〜さけのわデータで探す自分好みの酒〜好みの日本酒を呑みたい! 〜さけのわデータで探す自分好みの酒〜
好みの日本酒を呑みたい! 〜さけのわデータで探す自分好みの酒〜
 
令和から本気出す
令和から本気出す令和から本気出す
令和から本気出す
 
{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
 
20170923 excelユーザーのためのr入門
20170923 excelユーザーのためのr入門20170923 excelユーザーのためのr入門
20170923 excelユーザーのためのr入門
 
mxnetで頑張る深層学習
mxnetで頑張る深層学習mxnetで頑張る深層学習
mxnetで頑張る深層学習
 
可視化周辺の進化がヤヴァイ 〜2016〜
可視化周辺の進化がヤヴァイ 〜2016〜可視化周辺の進化がヤヴァイ 〜2016〜
可視化周辺の進化がヤヴァイ 〜2016〜
 
Rによるウイスキー分析
Rによるウイスキー分析Rによるウイスキー分析
Rによるウイスキー分析
 
20160311 基礎からのベイズ統計学輪読会第6章 公開ver
20160311 基礎からのベイズ統計学輪読会第6章 公開ver20160311 基礎からのベイズ統計学輪読会第6章 公開ver
20160311 基礎からのベイズ統計学輪読会第6章 公開ver
 
20140625 rでのデータ分析(仮) for_tokyor
20140625 rでのデータ分析(仮) for_tokyor20140625 rでのデータ分析(仮) for_tokyor
20140625 rでのデータ分析(仮) for_tokyor
 
lubridateパッケージ入門
lubridateパッケージ入門lubridateパッケージ入門
lubridateパッケージ入門
 
20150329 tokyo r47
20150329 tokyo r4720150329 tokyo r47
20150329 tokyo r47
 
20140920 tokyo r43
20140920 tokyo r4320140920 tokyo r43
20140920 tokyo r43
 
Google's r style guideのすゝめ
Google's r style guideのすゝめGoogle's r style guideのすゝめ
Google's r style guideのすゝめ
 

Recently uploaded

Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
amitlee9823
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 

Recently uploaded (20)

BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
ELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptxELKO dropshipping via API with DroFx.pptx
ELKO dropshipping via API with DroFx.pptx
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 

{shiny}と{leaflet}による地図アプリ開発Tips

  • 1.
  • 2. > me $name [1] "Takashi Kitano" $twitter [1] "@kashitan" $work_in [1] " " %>% " "
  • 3.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. glimpse(choices) List of 4 $ : Named chr [1:58] "11101" "11102" "11103" "11104" ... ..- attr(*, "names")= chr [1:58] " " " " " " " " ... $ : Named chr [1:36] "12101" "12102" "12103" "12104" ... ..- attr(*, "names")= chr [1:36] " " " " " " " " ... $ : Named chr [1:51] "13101" "13102" "13103" "13104" ... ..- attr(*, "names")= chr [1:51] " " " " " " " " ...
  • 10. names(choices) [1] " " " " " " " " choices[[" "]] "13101" "13102" "13103" "13104" "13105" "13106" "13107" "13108" "13109" "13110" "13111" "13112" "13113" "13114" "13115" "13116" "13117" "13118"
  • 11. selectInput( inputId = "pref", label = " ", choices = names(choices), selected = " ", width = "100%" ) selectInput( inputId = "city", label = " ", # choices = choices$` `, selected = "13112", width = "100%" )
  • 12. server <- function(input, output, session) { observe({ city_choices <- choices[[input$pref]] city <- input$city # # if (!(city %in% city_choices)) { city <- city_choices[1] } updateSelectInput( session, inputId = “city", choices = city_choices, selected = city ) }) }
  • 13.
  • 14.
  • 15.
  • 16. # tags$style(type = "text/css", "#map {height: calc(90vh - 80px) ! important;}"), leafletOutput("map")
  • 17. output$map <- leaflet::renderLeaflet({ leaflet::leaflet() %>% leaflet::addProviderTiles(providers$CartoDB.Positron) })
  • 18. observe({ pal <- leaflet::colorNumeric("Spectral", dat.sub()$n, reverse = TRUE) map <- leaflet::leafletProxy("map", data = dat.sub()) %>% leaflet::clearShapes() %>% leaflet::clearControls() %>% leaflet::addPolygons(fillColor = ~ pal(n), color = "gray", popup = ~ NAME, weight = 1, fillOpacity = 0.8) %>% leaflet::addLegend("bottomright", pal = pal, values = ~ n, title = "Population", opacity = 1) map })
  • 19. observe({ pal <- leaflet::colorNumeric("Spectral", dat.sub()$n, reverse = TRUE) map <- leaflet::leafletProxy("map", data = dat.sub()) %>% leaflet::clearShapes() %>% leaflet::clearControls() %>% leaflet::addPolygons(fillColor = ~ pal(n), color = "gray", popup = ~ NAME, weight = 1, fillOpacity = 0.8) %>% leaflet::addLegend("bottomright", pal = pal, values = ~ n, title = "Population", opacity = 1) map })
  • 20.
  • 21.
  • 22.
  • 23. is.fitBounds <- FALSE observeEvent(input$city, { is.fitBounds <<- TRUE }) observe({ if (is.fitBounds) { # bbox <- dat.sub() %>% sf::st_bbox() names(bbox) <- NULL map <- map %>% leaflet::fitBounds(bbox[1], bbox[2], bbox[3], bbox[4]) is.fitBounds <<- FALSE } map
  • 24. is.fitBounds <- FALSE observeEvent(input$city, { is.fitBounds <<- TRUE }) observe({ if (is.fitBounds) { # bbox <- dat.sub() %>% sf::st_bbox() names(bbox) <- NULL map <- map %>% leaflet::fitBounds(bbox[1], bbox[2], bbox[3], bbox[4]) is.fitBounds <<- FALSE } map
  • 25.
  • 26.
  • 27.
  • 28. observeEvent(input$map_shape_click, { p <- input$map_shape_click # shp.sub <- shp[[input$pref]] %>% dplyr::filter(stringr::str_sub(KEY_CODE, 1, 5) %in% choices[[input$pref]]) # ind <- sf::st_point(c(p$lng, p$lat), dim = "XY") %>% sf::st_within(shp.sub) %>% unlist() })
  • 29. observeEvent(input$map_shape_click, { p <- input$map_shape_click # shp.sub <- shp[[input$pref]] %>% dplyr::filter(stringr::str_sub(KEY_CODE, 1, 5) %in% choices[[input$pref]]) # ind <- sf::st_point(c(p$lng, p$lat), dim = "XY") %>% sf::st_within(shp.sub) %>% unlist() })