Basic example of fillPage in Shiny - How does it work?

↘锁芯ラ 提交于 2021-01-27 17:16:21

问题


i don´t get how i can get a plot to fill my dashboard completely (besides the header). I think i have to use fillPage, but i can´t get it to work. Here is my example. I´m thankful for any hints!

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)

回答1:


This should do the job:

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)



来源:https://stackoverflow.com/questions/51096375/basic-example-of-fillpage-in-shiny-how-does-it-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!