[英]Problems scaling map. Shiny + leaflet
I cant have "full screen" map in my shiny app, because when I used "100%" parameter, the map disappears... 我无法在闪亮的应用程序中显示“全屏”地图,因为当我使用“ 100%”参数时,地图消失了...
ui <- fluidPage(
leafletOutput("mymap", height = "100%", width = "100%"),
But when I do this 但是当我这样做时
ui <- fluidPage(
leafletOutput("mymap"),
there is no problems, but there is a half with map and a half in blank. 没问题,但是地图有一半,空白处有一半。 And I need it to be full screen 我需要全屏显示
I tried 我试过了
leafletOutput("mymap", height = 800, width = 1300)
But it is not what I need, because it didnt scale to the window, thats why i preffer the "100%" parameter. 但这不是我所需要的,因为它没有缩放到窗口,这就是为什么我使用“ 100%”参数。
Well I guess with 100% height you mean "fit to screen/window"? 好吧,我想100%的高度是指“适合屏幕/窗口”吗?
jscode <- '
$(document).on("shiny:connected", function(e) {
var jsHeight = window.innerHeight;
Shiny.onInputChange("GetScreenHeight",jsHeight);
});
'
library(shiny)
library(leaflet)
r_colors <- rgb(t(col2rgb(colors()) / 255))
names(r_colors) <- colors()
ui <- fluidPage(
p(),
tags$script(jscode),
uiOutput("leafl"),
actionButton("recalc", "New points")
)
server <- function(input, output, session) {
points <- eventReactive(input$recalc, {
cbind(rnorm(40) * 2 + 13, rnorm(40) + 48)
}, ignoreNULL = FALSE)
output$mymap <- renderLeaflet({
leaflet() %>%
addProviderTiles("Stamen.TonerLite",
options = providerTileOptions(noWrap = TRUE)
) %>%
addMarkers(data = points())
})
output$leafl <- renderUI({
if(!is.null(input$GetScreenHeight)){
width <- session$clientData$output_image1_width
print(session$clientData)
height <- session$clientData$output_image1_height
leafletOutput("mymap", width = "100%", height = input$GetScreenHeight)
}
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.