R闪亮的ColVis和数据表搜索

时间:2015-07-04 18:38:30

标签: regex r datatables shiny

我让TableTools和ColVis一起工作,但是,正如另一篇文章(R shiny DataTables ColVis behavior)中所解释的那样,当单击“显示/隐藏列”按钮时,列表会混合下面表格中的值,并且我不能让名单消失。

在该帖子中提到闪亮的atm与当前的data.table版本不兼容,并且我想知道是否还有其他解决方案。这是我的代码:

ui.R

 library(shiny)
 library(shinythemes)
 library(ggplot2)

addResourcePath('datatables','\\Users\\Ser\\Downloads\\DataTables-1.10.7\\DataTables-1.10.7\\media')
addResourcePath('tabletools','\\Users\\Ser\\Downloads\\TableTools-2.2.4\\TableTools-2.2.4')

shinyUI(fluidPage(theme = shinytheme("Journal"),


  tags$head(
tags$style(HTML("
  @import url('//fonts.googleapis.com/css?family=Lobster|Cabin:400,700');
                "))
),

  headerPanel(
h1("List Manager", 
   style = "font-family: 'Lobster', cursive;
   font-weight: 500; line-height: 1.1; 
   color: #ad1d28;")),

sidebarLayout(
    sidebarPanel( 


#File Upload Manager
fileInput('file1', 'Choose file to upload'),

tagList(
  singleton(tags$head(tags$script(src='//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.7/js/jquery.dataTables.min.js',type='text/javascript'))),
  singleton(tags$head(tags$script(src='//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/js/TableTools.min.js',type='text/javascript'))),
  singleton(tags$head(tags$script(src='//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/js/ZeroClipboard.min.js',type='text/javascript'))),
  singleton(tags$head(tags$link(href='//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/css/TableTools.min.css',rel='stylesheet',type='text/css'))),
  singleton(tags$head(tags$script(src='//cdn.datatables.net/colvis/1.1.0/js/dataTables.colVis.min.js',type='text/javascript'))),
  singleton(tags$script(HTML("if (window.innerHeight < 400) alert('Screen too small');")))
)),

mainPanel(
dataTableOutput("mytable"))

  )))

server.R

shinyServer(function(input, output) {
  output$mytable = renderDataTable({

inFile <- input$file1
if (is.null(inFile))
  return(NULL)
read.table(inFile$datapath, header=TRUE, sep='')

  }, options = list(
"dom" = 'TC<"clear">lfrtip',
"colVis" = list(
  "activate"="click",
  "align"="right"),
"oTableTools" = list(
  "sSwfPath" = "//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/swf/copy_csv_xls.swf",
  "aButtons" = list(
    "copy",
    "print",
    list("sExtends" = "collection",
         "sButtonText" = "Save",
         "aButtons" = c("csv","xls")
    )
  )
)
  )
  )
})

我还有另一个问题:我想搜索&#34;&lt;&#34;或&#34;&gt;&#34;表底部搜索框中的值,但我无法使其工作。我不知道是否必须在代码中添加任何内容以便可以完成(例如&#34; regex&#34;或类似代码)。

1 个答案:

答案 0 :(得分:0)

您可以尝试 DT 包,而不是自己攻击JS库。这是一个最小的例子:

library(shiny)
library(DT)
library(shinythemes)
shinyApp(
  ui = fluidPage(
    theme = shinytheme('journal'),
    fluidRow(column(12, DT::dataTableOutput('foo')))
  ),
  server = function(input, output) {
    output$foo = DT::renderDataTable(
      iris,
      filter = 'bottom',
      extensions = list(ColVis = list(activate= "click", align = "right")),
      options = list(dom = 'C<"clear">lfrtip')
    )
  }
)

有关DataTables扩展程序的详细信息,请参阅http://rstudio.github.io/DT/extensions.html