简体   繁体   English

如何在R闪亮的顶部放置renderDataTable的过滤器

[英]How to put filter of renderDataTable at the top in R shiny

I am using renderDataTable in R & Shiny to present my data, but the filter is positioned at the bottom of table. 我在R&Shiny中使用renderDataTable来呈现我的数据,但过滤器位于表的底部。 Is there any way to put it at the top of the table? 有没有办法把它放在桌子的顶部? Thanks in advance! 提前致谢!

BTW, where can I find the option list of renderDataTable ? 顺便说一下,在哪里可以找到renderDataTable的选项列表?

  mainPanel(
    tabsetPanel(
      tabPanel("Table",tableOutput("values")),
      tabPanel("Tree Plot",plotOutput("plot")),
      tabPanel("Segment Data",dataTableOutput("obs"))

I'm not familiar with CSS, can anyone give me some advice on how to edit CSS inside R function? 我不熟悉CSS,有人可以给我一些关于如何在R函数内编辑CSS的建议吗?

Another option is to modify the CSS. 另一种选择是修改CSS。 with this line 用这条线

tags$head(tags$style("tfoot {display: table-header-group;}"))

You put this into your ui.R file like this 你把它放到你的ui.R文件中就像这样

,tabPanel("MeSH"          ,tags$head(tags$style("tfoot {display: table-header-group;}"))
    ,fluidRow( ...

This : How to place DataTables column filter on top : can help you with the CSS you'll need to modify to get the filter at the top. 这个: 如何在顶部放置DataTables列过滤器 :可以帮助您修改CSS以使过滤器位于顶部。

You can look here : https://github.com/rstudio/shiny-examples/blob/master/012-datatables/server.R : for how to use the renderDataTable options and you should be able to see the correlation between the way those options are set and the options list for the jQuery DataTables proper. 您可以在这里查看: https//github.com/rstudio/shiny-examples/blob/master/012-datatables/server.R :关于如何使用renderDataTable选项,您应该能够看到方式之间的相关性这些选项已设置,jQuery DataTables的选项列表正确。

I know very little of css and I prefer to do as many as possible from the core script that I don't need to worry about making changes to the cosmetic thing here or there later. 我对css知之甚少,我更喜欢从核心脚本中尽可能多地做,我不需要担心在这里或之后对化妆品进行更改。 So I used the following approach by setting "filter = 'top'" when calling renderDataTable() on server. 所以我在服务器上调用renderDataTable()时通过设置“filter ='top'”来使用以下方法。 No CSS required at all. 根本不需要CSS。

mainPanel("Data",
           dataTableOutput("datatbl")) 

server.R server.R

# create data table output
output$datatbl <- DT::renderDataTable(

  #data
  dt2(), rownames = FALSE,

  # column filter on the top
  filter = 'top', server = TRUE,

  # autoWidth
  options = list(autoWidth = TRUE))

Note that I only use renderDataTable() to call the function, to use arguments in the function we cannot write it as programming codes in {}, I guess. 请注意,我只使用renderDataTable()来调用函数,在函数中使用参数我们无法将其写为{}中的编程代码,我猜。 Let me know if it works for you. 请让我知道这对你有没有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM