缩放地图时出现问题.闪亮+传单



我不能在我的闪亮应用程序中拥有"全屏"地图,因为当我使用"100%"参数时,地图消失了......

ui <- fluidPage(
  leafletOutput("mymap", height = "100%", width = "100%"),

但是当我这样做时

ui <- fluidPage(
  leafletOutput("mymap"),

没有问题,但有一半有地图,一半是空白的。我需要它是全屏的

我试过了

leafletOutput("mymap", height = 800, width = 1300)

但这不是我需要的,因为它没有扩展到窗口,这就是我使用"100%"参数的原因。

好吧,

我想 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)

最新更新