생각
이를 위해 사용해야하는 몇 가지 자바 스크립트 코드 this R 전단지 문서 페이지에서 언급 한대로 기능 htmlwidgets::onRender()
를 사용하여 주입.
javascript 생성 된 리플릿 HTML 파일의 헤드에 문자열을 삽입하여 페이지를 응답하도록하는 jquery 코드 (리플릿 R 패키지에 포함 된 javascript 라이브러리)가 필요합니다. reproductible 코드 출력 example.html
의 응답의
# load leaflet library
library(leaflet)
# create the string for responsiveness that will be injected in the <head> section of the leaflet output html file. Note that the quotes were escaped using the backslash character : `\`.
responsiveness = "\'<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\'"
# build a leaflet map with a stamen background
example.map <- leaflet() %>%
addProviderTiles(group = "Stamen",
providers$Stamen.Toner,
options = providerTileOptions(opacity = 0.25)
) %>%
# add the javascript for responsivness
htmlwidgets::onRender(paste0("
function(el, x) {
$('head').append(",responsiveness,");
}"))
# show the map
example.map
# output an save the html file of the leaflet map in the root of your working directory
saveWidget(widget=example.map,
file= "example.html",
selfcontained = TRUE
)
검증과
javascript $('head').append('<meta name="viewport" content="width=device-width, initial-scale=1.0">')
R 구현 이제지도가 반응해야한다 : 여기에 자바 스크립트/jQuery 코드입니다. 다음과 같은 두 가지 방법을 확인할 수 있습니다
는 텍스트 편집기로 만든 example.html
파일을 열고 HTML 태그 <meta name="viewport" content="width=device-width, initial-scale=1.0">
이 파일의 head
부분에 있는지 확인하십시오.
브라우저에서 example.html
파일을여십시오. 크롬을 마우스 오른쪽 버튼으로 클릭하고 검사 한 다음 휴대 전화 아이콘을 클릭하면 페이지가 휴대 전화로 렌더링 된 것으로 표시됩니다. 그렇다면 줌 버튼에 쉽게 접근 할 수 있어야합니다 (큰 크기).