Last active
November 11, 2015 11:49
-
-
Save yamano357/ce74577c6b675a350351 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Windows環境で{leaflet}のpopup引数を指定すると表示ができない症状について | |
library(dplyr) | |
library(readr) | |
library(stringr) | |
library(leaflet) | |
plotLeaflet <- function (plot_obj){ | |
return( | |
plot_obj %>% | |
leaflet::leaflet() %>% | |
leaflet::addCircles( | |
lng = ~longitude, lat = ~latitude, | |
stroke = FALSE, | |
popup = ~ htmltools::htmlEscape(text = station) | |
) %>% | |
leaflet::addTiles() | |
) | |
} | |
download.file(url = "https://gist.githubusercontent.com/yamano357/929eec744d72ee88fa0b/raw/1bb01fe844f2ae1d6eef8664cfb922d61843aff4/station.csv", destfile = "station.csv") | |
test_ok <- dplyr::data_frame(station = "伊予西条", longitude = 133.1876, latitude = 33.91246) %>% | |
# Source: local data frame [1 x 3] | |
# station longitude latitude | |
# (chr) (dbl) (dbl) | |
# 1 伊予西条 133.1876 33.91246 | |
test_ok2 <- readr::read_delim(file = "station.csv", col_names = TRUE, delim = ",") %>% | |
# Source: local data frame [1 x 3] | |
# station longitude latitude | |
# (chr) (dbl) (dbl) | |
# 1 莨贋コ郁・ソ譚。 133.1876 33.91246 | |
test_ng <- test_ok2 %>% | |
dplyr::mutate(station = stringr::str_conv(string = .$station, encoding = "UTF-8")) %>% | |
# Source: local data frame [1 x 3] | |
# station longitude latitude | |
# (chr) (dbl) (dbl) | |
# 1 伊予西条 133.1876 33.91246 | |
# Linux上だと全部同じ | |
charToRaw(x = test_ok$station) | |
# [1] 88 c9 97 5c 90 bc 8f f0 | |
charToRaw(x = test_ok2$station) | |
# [1] e4 bc 8a e4 ba 88 e8 a5 bf e6 9d a1 | |
charToRaw(x = test_ng$station) | |
# [1] e4 bc 8a e4 ba 88 e8 a5 bf e6 9d a1 | |
# Linux上だとtest_okも"UTF-8" | |
Encoding(x = test_ok$station) | |
# [1] "unknown" | |
Encoding(x = test_ok2$station) | |
# [1] "unknown" | |
Encoding(x = test_ng$station) | |
# [1] "UTF-8" | |
# Linux上だと全部OK | |
plotLeaflet(plot_obj = test_ok) # OK(ただし、ポップアップ文字化け) | |
plotLeaflet(plot_obj = test_ok2) # OK | |
plotLeaflet(plot_obj = test_ng) # NG(RStudio上のViewerタブが灰色) | |
Encoding(x = test_ng$station) <- "unknown" | |
plotLeaflet(plot_obj = test_ng)# OKに |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment