我喜欢调整行的高度,以便布局“侧边栏面板加主面板(2行X 2列)”填充浏览器窗口的可用区域,因此它允许所有可视化这些数字没有向下滚动页面。
在默认选项下,需要向下滚动页面才能完全看到第二行。为了解决这个问题,我在' renderPlot '中使用了' height '[即 height = 200 ]和' style 'in'列'[ie, div(style =“height:100px”)]。 renderplot 中的' height '减小了地图尺寸,行高在' div(style =“height:100px”)'中随高度值变化但是大约@ 高度:70px 行高是固定的;即使像素数减少,行高也没有进一步减小; hr()绘制一条水平线,它可以了解 style 中 height 的不同值的行高如何变化。问题是,在这个最低值下,底部图需要向下滚动页面,而我希望'侧边栏面板加上主面板(有多行)'位于浏览器窗口的可用区域中,以便我不需要向下滚动页面。非常感谢您的帮助。
以下链接在某种程度上非常有用:
Control the height in fluidRow in R shiny和Scale and size of plot in RStudio shiny
以下是生成侧边栏面板以及2 X 1 的主面板的示例代码:
library(shiny)
library(ggplot2)
ui<- pageWithSidebar(
headerPanel('data:Iris'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(iris)),
selectInput('ycol', 'Y Variable (Plot 1)', names(iris),
selected=names(iris)[[2]]),
selectInput('ycol2', 'Y Variable (Plot 2)', names(iris),
selected=names(iris)[[3]])
),
mainPanel(
fluidRow(
column(6,plotOutput('plot1'),div(style = "height:100px"))
),
hr(),
fluidRow(
column(6,plotOutput('plot2'))
)
)
)
server <- function(input, output) {
# pass data of selected input variables from the dataframe to ggplot
# Plot 1
output$plot1 <- renderPlot({
ggplot(iris,aes_string(input$xcol,input$ycol))+geom_point()
},height = 200)
# Plot 2
output$plot2 <- renderPlot({
ggplot(iris,aes_string(input$xcol,input$ycol2))+geom_point()
},height = 200)
}
shinyApp(ui =ui, server = server)
如图所示,第二行中的绘图需要向下滚动网页才能完全看到它。
答案 0 :(得分:1)
实际上plotOutput
的默认高度为“400px”。将行更改为
column(6,plotOutput('plot1', height="200px"))