Reduce font size in renderDataTable in a shiny presentation

徘徊边缘 提交于 2020-01-05 05:33:09

问题


I'm using a shiny presentation in order to display two tables. Here's my code:

tabsetPanel(
  tabPanel('iris',
           renderDataTable(iris,options = 
list(lengthMenu = c(5, 10), pageLength = 5, scrollX = TRUE), escape = 
FALSE)), 
  tabPanel('mtcars',
           renderDataTable(mtcars, options = list(lengthMenu 
= c(5, 10), pageLength = 5, scrollX = TRUE), escape = FALSE))
)

I would like to shrink the size of the tables. I tried adding div in the following way:

div(renderDataTable(mtcars, options = list(lengthMenu 
= c(5, 10), pageLength = 5, scrollX = TRUE), escape = FALSE), style = "font-
size:50% ")

But this is not working.

I also tried doing this:

mainPanel( 
  tabsetPanel(id='BLMS', 
              tabPanel("iris", fluidRow(div(dataTableOutput(outputId="iris"),  
style = "font-size:50%"))), 
              tabPanel("mtcars", 
fluidRow(div(dataTableOutput(outputId="mtcars"),  style = "font-size:50%")))
              )
  )  

output$iris<- renderDataTable({iris}, options = list(lengthMenu = c(5, 10), 
pageLength = 5, scrollX = TRUE))

output$mtcars<- renderDataTable({mtcars},options = list(lengthMenu = c(5, 
10), pageLength = 5, scrollX = TRUE))

But It's displaying a table cut in half in the presentation.


回答1:


If you want to reduce the size of the table, put it in a column with width < 12. If you furthermore want to decrease the font size, shinyjs::inlineCSS comes in handy:

library(DT)
library(shinyjs)
shinyApp(shinyUI(
  fluidPage(column(width=6, dataTableOutput("iris")),
        useShinyjs(),
        inlineCSS(list("table" = "font-size: 8px")))
  ),

  shinyServer(function(input, output) {
    output$iris = renderDataTable({
        datatable(iris,options =
                    list(lengthMenu = c(5, 10), pageLength = 5, scrollX = TRUE), escape =
                    FALSE)
    })
  })
)

edit: as it was pointed out, adding a style command to your div that contains the table works even better: fluidPage(style = "font-size: 75%; width: 75%", dataTableOutput("iris")))



来源:https://stackoverflow.com/questions/44455263/reduce-font-size-in-renderdatatable-in-a-shiny-presentation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!