我正在构建一个没有仪表板结构的 Shiny 应用程序,因为我想使用左侧作为页面的侧边栏,而不是导航到不同的页面。并使导航栏成为用户导航到不同页面的位置。
如果不使用shinydashboard/flexdashboard结构,valueBox将无法正确显示。有谁知道如何在不依赖仪表板结构的情况下利用 valueBox 设计?
我从 stackOverflow 找到了一个示例,并针对这个问题重新调整了用途:
没有仪表板结构/valueBox 的设计会丢失
library(shiny)
library(shinydashboard)
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
valueBoxOutput("vbox1", width = 2)
)
)
)
server <- function(input, output) {
output$vbox1 <- shinydashboard::renderValueBox({
d <- 42
shinydashboard::valueBox( d, "Ccy")
})
}
shinyApp(ui, server)
我希望在没有仪表板结构的情况下实现仪表板/设计的正常方式 只有 UI 部分不同
library(shiny)
library(shinydashboard)
ui <- dashboardPage(skin = "black",
dashboardHeader(title = "test"),
dashboardSidebar(
sidebarMenu()),
dashboardBody(
fluidRow(
valueBoxOutput("vbox1", width = 2))))
server <- function(input, output) {
output$vbox1 <- shinydashboard::renderValueBox({
d <- 42
shinydashboard::valueBox( d, "Ccy")
})
}
shinyApp(ui, server)
最佳答案
您可以使用shinyWidgets
中的useShinydashboard
来实现所需的结果:
library(shiny)
library(shinydashboard)
library(shinyWidgets)
ui <- fluidPage(
useShinydashboard(),
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
valueBoxOutput("vbox1", width = 2)
)
)
)
server <- function(input, output) {
output$vbox1 <- shinydashboard::renderValueBox({
d <- 42
shinydashboard::valueBox( d, "Ccy")
})
}
shinyApp(ui, server)
关于r - 如何在没有仪表板结构的 ShinyApp 中利用 valuebox?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66015570/