gpt4 book ai didi

html - Shiny 的情节高度在不同的桌面上表现不同

转载 作者:行者123 更新时间:2023-11-28 00:32:01 27 4
gpt4 key购买 nike

我正在尝试制作一个自定义用户界面,其中我必须在每个选项卡中绘制 4 个图,
但是我在绘图渲染上滚动,当我添加高度时 240 滚动条消失并且它适用于相同大小的桌面但它在不同大小的桌面上表现不同并且我再次获得滚动条。

动机是在没有滚动条的情况下适应屏幕中的情节,我也想得到一个反馈,我是否以正确的方式创建 UI

谢谢

用户界面

navbarPage("NarBar",
tabPanel("Tab1",
column(12,
column(4,
column(12,
checkboxInput("ID1", "Checkbox1", FALSE)
),
column(12,
checkboxInput("ID2", "Checkbox2", FALSE)
)
),
column(8,
column(3,
selectInput("ID1", "Select1:",
c("A" = "a",
"B" = "b",
"C" = "c"))
),
column(3,
selectInput("ID2", "Select2:",
c("A" = "a",
"B" = "b",
"C" = "c"))
),
column(3,
selectInput("ID3", "Select3:",
c("A" = "a",
"B" = "b",
"C" = "c"))
),
column(3,
selectInput("ID4", "Select4:",
c("A" = "a",
"B" = "b",
"C" = "c")
)
)
)
),
column(12,
column(4,
column(12,
selectInput("ID1", "Select1:",
c("A" = "a",
"B" = "b",
"C" = "c")
)
),
column(12,
selectInput("ID2", "Select2:",
c("A" = "a",
"B" = "b",
"C" = "c")
)
),
column(12,
selectInput("ID3", "Select3:",
c("A" = "a",
"B" = "b",
"C" = "c")
)
),
column(12,
selectInput("ID4", "Select4:",
c("A" = "a",
"B" = "b",
"C" = "c")
)
),
column(12,
selectInput("ID5", "Select5:",
c("A" = "a",
"B" = "b",
"C" = "c")
)
),
column(12,
selectInput("ID6", "Select6:",
c("A" = "a",
"B" = "b",
"C" = "c")
)
)
),
column(width = 8,
tabsetPanel(
tabPanel(title = 'Tab1',
column(width = 6,
plotOutput('plot1',height = 240)
),
column(width = 6,
plotOutput('plot2',height = 240)
),
column(width = 6,
plotOutput('plot3',height = 240)
),
column(width = 6,
plotOutput('plot4',height = 240)
)
),
tabPanel(title = 'Tab2',
column(width = 6,
plotOutput('plot5',height = 240)
),
column(width = 6,
plotOutput('plot6',height = 240)
),
column(width = 6,
plotOutput('plot7',height = 240)
),
column(width = 6,
plotOutput('plot8',height = 240)
)
),
tabPanel(title = 'Tab3',
column(width = 6,
plotOutput('plot9',height = 240)
),
column(width = 6,
plotOutput('plot10',height = 240)
),
column(width = 6,
plotOutput('plot11',height = 240)
),
column(width = 6,
plotOutput('plot12',height = 240)
)
)
)
)
)
),

tabPanel("Tab 2"
),
tabPanel("Tab 3"
),
tabPanel("Tab 4"
)
)

server 对每个 plotOutput 使用相同的 plot

function(input, output, session) {

output$plot1 <- renderPlot({ #just use the same plot on different plots like plot2,plot3,etc
cars2 <- cars + rnorm(nrow(cars))
plot(cars2)
})

}

最佳答案

首先,你的代码有很多重复的部分。我们可以使用 lapply 更有效地创建这些部分,如下所示。

基于这个答案(https://stackoverflow.com/a/26785047/7669809),我添加了 tags$head(tags$style(".shiny-plot-output{height:40vh !important;}")) 到你的导航栏页面。它似乎工作。您可以将 40vh 更改为您想要使用的其他号码。

library(shiny)
library(htmlwidgets)

ui <- navbarPage("NarBar",
tags$head(tags$style(".shiny-plot-output{height:40vh !important;}")),
tabPanel("Tab1",
column(12,
column(4,
lapply(1:2, function(x){
column(12,
checkboxInput(paste0("ID", x),
paste0("Checkbox", x),
FALSE)
)
})
),
column(8,
lapply(1:4, function(x){
column(3,
selectInput(paste0("ID", x),
paste0("Select", x, ":"),
c("A" = "a",
"B" = "b",
"C" = "c")))
})
)
),
column(12,
column(4,
lapply(1:6, function(x){
column(12,
selectInput(paste0("ID", x),
paste0("Select", x, ":"),
c("A" = "a",
"B" = "b",
"C" = "c")
)
)
})
),
column(width = 8,
tabsetPanel(
tabPanel(title = 'Tab1',
lapply(1:4, function(x){
column(width = 6,
plotOutput(paste0('plot', x))
)
})
),
tabPanel(title = 'Tab2',
lapply(5:8, function(x){
column(width = 6,
plotOutput(paste0('plot', x))
)
})
),
tabPanel(title = 'Tab3',
lapply(9:12, function(x){
column(width = 6,
plotOutput(paste0('plot', x))
)
})
)
)
)
)
),

tabPanel("Tab 2"
),
tabPanel("Tab 3"
),
tabPanel("Tab 4"
)
)

server <- function(input, output, session) {

lapply(1:12, function(x) {
output[[paste0('plot', x)]] <- renderPlot({
cars2 <- cars + rnorm(nrow(cars))
plot(cars2)
})
})
}

shinyApp(ui, server)

关于html - Shiny 的情节高度在不同的桌面上表现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58467135/

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