我无法全屏播放"在我闪亮的应用程序中映射,因为当我使用" 100%"参数,地图消失......
ui <- fluidPage(
leafletOutput("mymap", height = "100%", width = "100%"),
但是当我这样做时
ui <- fluidPage(
leafletOutput("mymap"),
没有问题,但有一半有地图,一半有空白。我需要它全屏
我试过
leafletOutput("mymap", height = 800, width = 1300)
但这不是我需要的,因为它没有扩展到窗口,这就是为什么我喜欢&#34; 100%&#34;参数。
答案 0 :(得分:4)
嗯,我想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)