简体   繁体   English

R Shiny ColVis和数据表搜索

[英]R shiny ColVis and datatable search

I have TableTools and ColVis working together, but, as it was explained in another post ( R shiny DataTables ColVis behavior ), when clicking the Show/hide columns button, the list mixes up with the values in the table underneath, and I cannot make the list disappear. 我有TableTools和ColVis一起工作,但是,正如另一篇文章( R闪亮的DataTables ColVis行为 )中所述,单击“显示/隐藏列”按钮时,列表与下面表格中的值混合在一起,我无法列表消失了。

In that post is mentioned that shiny atm is not compatible with the current data.table version, and I'd like to know if there's any other solution around. 在那篇文章中提到闪亮的atm与当前的data.table版本不兼容,我想知道周围是否还有其他解决方案。 Here's my code: 这是我的代码:

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")
    )
  )
)
  )
  )
})

I also have another question: I'd like to search "<" or ">" values in the searchboxes at the bottom of the table, but I can't make it work. 我还有另一个问题:我想在表格底部的搜索框中搜索“ <”或“>”值,但无法使其正常工作。 I don't know if I have to add anything to the code so it can be done (such as "regex" or similar). 我不知道是否必须在代码中添加任何内容以便可以完成(例如“ regex”或类似内容)。

You may try the DT package instead of hacking the JS libraries by yourself. 您可以尝试使用DT软件包,而不是自己入侵JS库。 Here is a minimal example: 这是一个最小的示例:

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')
    )
  }
)

See http://rstudio.github.io/DT/extensions.html for more info on DataTables extensions. 有关DataTables扩展的更多信息,请参见http://rstudio.github.io/DT/extensions.html

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

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