r - 如何在没有仪表板结构的 ShinyApp 中利用 valuebox?

标签 r shiny shinydashboard shinyapps

我正在构建一个没有仪表板结构的 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/

相关文章:

r - 使 R Shiny 的 renderPlot 对文本输入使用react

r - 检测 Shiny 是否运行 R 代码

r - 显示模态 onclick 条形图

r - lintr 测试通过 devtools::check() 并通过 devtools::test() 失败

r - R ggplot2居中对齐多行标题

r - checkboxGroupInput 在 R shiny 中用于 ggplot

r - 如何更改 R Shiny 应用程序中图标的颜色?

R Shiny : Using numeric output variable as the initial value of slider

r - 有没有办法为rhandsontable中的不同行提供不同的下拉选项?

R 使用样本创建具有随机数的矩阵列