【发布时间】:2021-03-14 22:24:27
【问题描述】:
我是一个闪亮的新手,在我看来这是一个简单的问题。我有一个测试 app.R 读取数据框,询问用户开始日期并显示从该日期开始的时间序列面积图。 app.R 有效,但是当我扩大屏幕窗口的大小时,图表固定在从上到下的维度。从左到右的维度是灵活的。我怎样才能使从上到下的尺寸也灵活?我想让我的图形对象填满窗口。这是我的代表:
#library(Shiny)
#library(ggplot2)
a <- c(seq.Date(as.Date("2019-01-01"),as.Date("2019-06-01"),by="month"))
b <- c(4,7,2,9,13,6)
df <- data.frame(a=a,b=b)
ui <- fluidPage(
titlePanel("Test example"),
fluidRow(
sidebarPanel(
dateInput(inputId="StartDate",label="Please enter a start date:",
value="2019-01-01",min="2019-01-01",max="2019-06-01")
)
),
fluidRow(
column(12),
mainPanel(
plotOutput("distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
FirstDate <- input$StartDate
ggplot(filter(df,a>=as.Date(FirstDate)))+
geom_area(aes(x=a,y=b,fill="red"),alpha=0.4)+
geom_line(aes(x=a,y=b,colour="red"),size=1)+
theme(legend.position="none")
})
}
shinyApp(ui = ui, server = server)
谢谢。
菲利普
【问题讨论】: