我不知道如何获得可以完全填充仪表板的图(除标题外)。我认为我必须使用fillPage,但是我无法使它正常工作。这是我的例子。感谢您的提示!
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
packages <- c("tidyverse","shiny","shinydashboard","dashboardthemes","ggplot2")
ipak(packages)
#---------------------------------------------------------------------------------------------------------------------
ui <- dashboardPage(
dashboardHeader(title = "FullscreenDashboard", titleWidth = 450),
dashboardSidebar(disable = TRUE),
dashboardBody(
### change theme
shinyDashboardThemes(
theme = "grey_dark"
),
fillPage(
plotOutput("plot1", height = "100%", width = "100%")
)
)
)
server <- function(input, output, session){
output$plot1 <- renderPlot({ #reactivePlot
dat <- data.frame(
time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")),
total_bill = c(14.89, 17.23)
)
#Plot
p<-ggplot(data=dat, aes(x=time, y=total_bill, fill=time)) +
geom_bar(stat="identity")
print(p)
})
}
shinyApp(ui, server)
答案 0 :(得分:0)
这应该可以完成工作:
library(shiny)
library(shinydashboard)
library(dashboardthemes)
library(ggplot2)
ui <- dashboardPage(
dashboardHeader(title = "FullscreenDashboard", titleWidth = 450),
dashboardSidebar(disable = T),
dashboardBody(
### change theme
shinyDashboardThemes(
theme = "grey_dark"
),
fillPage(
tags$style(type = "text/css", "#plot1 {height: calc(100vh - 80px) !important;}"),
plotOutput("plot1", width = "100%",height = "100%")
)
)
)
server <- function(input, output, session){
output$plot1 <- renderPlot({ #reactivePlot
dat <- data.frame(
time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")),
total_bill = c(14.89, 17.23)
)
#Plot
p<-ggplot(data=dat, aes(x=time, y=total_bill, fill=time)) +
geom_bar(stat="identity")
p
})
}
shinyApp(ui, server)