【发布时间】:2022-11-04 00:28:30
【问题描述】:
我想创建 shinyDashboard valueBoxes。这些数量取决于选择的输入,所以我按照this example 进行渲染n使用 renderUI、htmlOutput 和 tagList 的 valueBoxes。但是,当我这样做时,valueBox 中的宽度参数似乎被忽略了,并且 valueBoxes 占据了页面的剩余宽度并垂直堆叠。如果在 UI 中手动呈现,它们的宽度是正确的,并且位于单个流畅的行上。
这是一个例子。这里 valueBoxes 的数量被硬编码为 3,但实际上这将由动态数据确定:
library(shiny)
library(shinyWidgets)
library(shinydashboard)
# Define UI for application that draws a histogram
ui <- fluidPage(
useShinydashboard(),
# Application title
titlePanel(title = 'Title'),
sidebarLayout(
sidebarPanel(width = "3",
selectInput(inputId = 'pick', 'Pick a letter',
choices = c('A','B','C'))
),
mainPanel(
uiOutput("stats")
)
)
)
server <- function(input, output, session) {
#how many statistics to show - in reality this will be dynamic
nstats <- 3
stats <- c(-10,0,10)
#dynamically create the right number of htmlOutputs
#https://stackoverflow.com/questions/31686773/shiny-dynamic-number-of-output-elements-plots
output$stats <- renderUI({
vboxes <- lapply(1:nstats, function(i) {
outputId <- paste0("valuebox_", i)
htmlOutput(outputId)
})
tagList(vboxes)
})
#now populate these with valueboxes containing the ith statistic
for(i in 1:nstats){
local({
#my_i <- i
outputId <- paste0("valuebox_", i)
temp <- stats[i]
output[[outputId]] <- renderValueBox({
valueBox(
subtitle = 'Change measure',
width = 2,
value = paste0(temp,"%"),
icon = icon('chart-line')
)
})
})
}
}
# Run the application
shinyApp(ui = ui, server = server)
这将生成以下内容,其中 valueBoxes 占据了所有 9 列,而不是每列 2 列。
我在 htmlOutput 中尝试过 inline=TRUE 但这没有什么区别。如何使 width=2 受到尊重,或者我需要将它移到哪里?谢谢
【问题讨论】:
标签: r shiny shinydashboard