[英]How to make a ggmap fill the entire page of a R Shiny app?
我没有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.