gpt4 book ai didi

r - 在 R Shiny 应用程序中使用滚动条绘制大图

转载 作者:行者123 更新时间:2023-12-05 01:13:21 24 4
gpt4 key购买 nike

我想在 Shiny 应用程序中为绘图添加一个滚动条,但是只有垂直滚动条出现而水平滚动条没有出现。我在此处附加了一个包含最少元素的 Shiny 小应用程序来演示该问题。

cat("\014")
unlink(".RData")
rm(list=ls(all.names = TRUE))

# A basic shiny app with a plotOutput
shinyApp(
ui = fluidPage(
sidebarLayout(
sidebarPanel(
),
mainPanel(
column(6,(div(style='width:200px;overflow-x: scroll;height:200px;overflow-y: scroll;',
uiOutput("plot"))) )

)
)
),
server = function(input, output) {
output$plot <- renderUI({
output$plot2 <- renderPlot(plot(cars))
plotOutput('plot2')
})
}
)

最佳答案

默认的 renderPlot(width="auto") 导致它从默认的 plotOutput(width="100%") 继承宽度。这意味着绘图被绘制到 div 的大小,这里你给它是 200px,因此不需要溢出。如果您明确指定 renderPlot(width=300)plotOutput(width="300px") 的宽度,则溢出将处于事件状态(注意前者是整数,后者是是字符)。

shinyApp(
ui = fluidPage(
sidebarLayout(
sidebarPanel(
),
mainPanel(
column(6,(div(style='width:200px;overflow-x: scroll;height:200px;overflow-y: scroll;',
uiOutput("plot"))) )

)
)
),
server = function(input, output) {
output$plot <- renderUI({
output$plot2 <- renderPlot(plot(cars),width=300) # either will
plotOutput('plot2',width='300px') # work
})
}
)

关于r - 在 R Shiny 应用程序中使用滚动条绘制大图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60437573/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com