微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Shiny Dashboard Box 覆盖 Kable 样式选项

如何解决Shiny Dashboard Box 覆盖 Kable 样式选项

我已经搜索了很多关于这个问题的答案,但没有找到我正在寻找的解决方案。

在创建 Kable 时,我可以完全按照我想要的桌子来设计样式,而且我喜欢它。那里没有问题。但是,当我将表格输出到正在构建的 Shiny 仪表板中并将其放入一个盒子中时,Shiny 正在剥离我在原始 Kable 中看到的所有格式和样式。它导致表格与我原来的完全不同,我不知道如何修复它。

如示例中所示,我已将 Kable 样式从 kable_classic 更改为 kable_styling,但是我得到的表格在图表上带有水平线,这也不是我想要的基于我的原始样式的表格。关于如何在 ShinyDashboard 中复制我想要的表格的任何想法?

所需表:

library(shiny)
library(shinydashboard)
library(tidyverse)
library(kableExtra)

#Load some data
df <- mtcars[1:6,1:4]

#Craft the html kable,which is what I want it to look like.
knitr::kable(df,"html") %>%
  kable_classic(full_width = T,html_font = "Cambria") %>%
  row_spec(0,bold = T) %>%
  add_indent(c(2:4))

输出推送到 Shiny Dashboard 后的表格:

ui <- dashboardPage(
  dashboardHeader(title = "My Dashboard"),dashboardSidebar(
    
    #### Dashboard Sidebar which displays the menu items and their icons.
    # contains: The list of side bar items and where each item is connected to in the UI
    sidebarMenu(
      menuItem("The Table",tabName = "Some data table",icon = icon("circle-arrow-up",lib = "glyphicon"))
    )
  ),dashboardBody(
      #Some dashboard body tab
      tabItem(tabName = "Some data table",tabsetPanel(
                tabPanel("My Kable",br(),fluidRow(
                           Box(title = "Not the right table",background = "light-blue",width = 12,tableOutput('datatable_1'))
                         ),fluidRow(
                           Box(title = "Alternate table,also not right",tableOutput('datatable_2'))
                         )
                )
      )
    )
  )
)


server <- function(input,output) { 
  output$datatable_1 <- function() {
    #Load some data
    df <- mtcars[1:6,1:4]
    
    #Craft the html kable,which is what I want it to look like.
    knitr::kable(df,"html") %>%
      kable_classic(full_width = T,html_font = "Cambria") %>%
      row_spec(0,bold = T) %>%
      add_indent(c(2:4))
  }
  
  output$datatable_2 <- function() {
    #Load some data
    df <- mtcars[1:6,"html") %>%
      kable_styling(full_width = T,bold = T) %>%
      add_indent(c(2:4))
  }
}

shinyApp(ui,server)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。