繁体   English   中英

如何使ggmap填充R Shiny应用程序的整个页面?

[英]How to make a ggmap fill the entire page of a R Shiny app?

请注意,我无法使用传单,因为我需要向地图添加自定义形状,而这在传单中是无法做到的。

所以下面的内容与我的想法类似,在其中添加了一些额外的geomPolygon图层的ggmap,然后它成为R Shiny页面的整个背景,并且小部件位于其顶部。

在此处输入图片说明

我没有ggmap API密钥,但是它的工作方式相同。 你们都使用CSS做到这一点。

您必须将主体高度和宽度设置为100%,这同样适用于绘图,因此它们会扩展到视口的宽度和高度。

最上面的所有内容都必须设置在position: absolute 这意味着div距顶部10像素,距右侧10像素。 absolutePanel会为您执行此设置,但是您可以在自己的CSS中执行此设置。

library(shiny)
library(leaflet)
library(RColorBrewer)
library(ggmap)


ui <- bootstrapPage(
  tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
  plotOutput("map", width = "100%", height = "100%"),
  absolutePanel(top = 10, right = 10,
                sliderInput("range", "Magnitudes", min(quakes$mag), max(quakes$mag),
                            value = range(quakes$mag), step = 0.1
                ),
                selectInput("colors", "Color Scheme",
                            rownames(subset(brewer.pal.info, category %in% c("seq", "div")))
                ),
                checkboxInput("legend", "Show legend", TRUE)
  )
)

server <- function(input, output, session) {

  output$map <- renderPlot({
    df <- data.frame(
      gp = factor(rep(letters[1:3], each = 10)),
      y = rnorm(30)
    )
    ds <- do.call(rbind, lapply(split(df, df$gp), function(d) {
      data.frame(mean = mean(d$y), sd = sd(d$y), gp = d$gp)
    }))


    ggplot(df, aes(gp, y)) +
      geom_point() +
      geom_point(data = ds, aes(y = mean), colour = 'red', size = 3)
  })

}

shinyApp(ui, server)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM