【问题标题】:R shiny table output with no padding没有填充的 R 闪亮表输出
【发布时间】:2016-12-07 17:09:08
【问题描述】:

我正在尝试制作一些表格没有填充的应用程序。

server <- function(input, output) {
    url = c("http://lorempixel.com/output/animals-q-c-480-480-7.jpg",
            "http://lorempixel.com/output/animals-q-c-480-480-1.jpg",
            "http://lorempixel.com/output/animals-q-c-480-480-8.jpg",
            "http://lorempixel.com/output/animals-q-c-480-480-6.jpg"
           )

image <- paste0( '<img src="',url,'" width=WIDTH></img>')
big.image   <- gsub("WIDTH", "200px", image)
small.image <- gsub("WIDTH", "100px", image)

big.df   <- data.frame(col1 = c(big.image[1], "Lorem", big.image[2], "Ipsum"), 
                       col2 = c(big.image[3], "Dolor", big.image[4], "Sit"))
small.df <- data.frame(col1 = c(small.image[1], "Lorem", small.image[2], "Ipsum"), 
                       col2 = c(small.image[3], "Dolor", small.image[4], "Sit"))


output$bigtable   <- renderTable(big.df, 
                             sanitize.text.function = function(x) x,
                             align='c',
                             colnames=F
                             )
output$smalltable <- renderTable(small.df, 
                             sanitize.text.function = function(x) x,
                             align='c',
                             colnames=F
                             )
}

ui <- fluidPage(
    mainPanel(tableOutput("bigtable"),
          tableOutput("smalltable")
    )
)

上面的代码创建了一个包含大图像表格和小图像表格的应用。我希望大图像表保持其当前间距,而小图像表没有间距。

ui <- fluidPage(
  tags$head(
   tags$style(HTML(
      "
    .table.shiny-table > thead > tr > th,
    .table.shiny-table > tbody > tr > th,
    .table.shiny-table > tfoot > tr > th,
    .table.shiny-table > thead > tr > td,
    .table.shiny-table > tbody > tr > td,
    .table.shiny-table > tfoot > tr > td {
    padding:0px; 

    }"))),
    mainPanel(tableOutput("bigtable"),
              tableOutput("smalltable")
    )
)

上面的代码会让所有的表格都没有间距,但我只希望第二个没有间距。我该如何解决这个问题?

【问题讨论】:

    标签: css r shiny html-table padding


    【解决方案1】:

    您可以使用自己的 id 调用第二张表:

    ui <- fluidPage(
      tags$head(
        tags$style(HTML(
          "
          #smalltable table > thead > tr > th,
          #smalltable table > tbody > tr > th,
          #smalltable table > tfoot > tr > th,
          #smalltable table > thead > tr > td,
          #smalltable table > tbody > tr > td,
          #smalltable table > tfoot > tr > td {
          padding:0px; 
    
          }"))),
        mainPanel(tableOutput("bigtable"),
                  tableOutput("smalltable")
        )
        )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-15
      • 2017-09-27
      • 2016-11-11
      • 2015-03-05
      • 2016-11-06
      • 1970-01-01
      相关资源
      最近更新 更多