R数据表按条件格式化按钮 [英] R datatable Button with conditional formatting

查看:192
本文介绍了R数据表按条件格式化按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个执行数据库查询的闪亮应用程序。 (简单)的想法是创建一个表,对列应用条件格式,并允许报告的表保存为excel。我尝试了不同的解决方案,但是使用datatable下载按钮似乎是最方便的。

I want to create a shiny app performing a database query. The (simple) idea is to create a table, apply conditional formatting on the columns and allow the reported table to save to excel. I tried different solutions, but the usage of a datatable download-button seemed the most convenient.

经过广泛的搜索,我设法应用了一个下载按钮(从github更新的dt-package),并在浏览器显示中应用特定的格式(formatStyle)应用程式这将使我以后能为独特的列应用条件格式。但是,使用保存按钮时,此格式会在保存的文件中丢失(请参见下面的代码片段)。

After extensive search I managed to apply a download button (updated dt-package from github) and to apply a specific formatting (formatStyle) in the browser display of the shiny-app. This will allow me in future to apply conditional formatting for the unique columns. However, when using the save-button this formatting gets lost in the saved file (See code fragment below).

据我了解,原因是formatStyle函数仅在datatable-call之后才应用。有没有办法早期应用formatStyle函数?创建resulttab对象的原因是formatStyle函数应用于由其名称选择的特定列,而tabelle-function则是在闪烁的反应环境中生成的。

In my understanding, the reason for this is that the formatStyle function is only applied after the datatable-call. Would there be a way to apply the formatStyle function earlier? The reason for creating the resulttab-object is, that the formatStyle-function is applied on specific columns selected by their names, while the tabelle-function is generated in the shiny reactive-environment.

output$tab <- DT::renderDataTable({
   resulttab <- tabelle() 
    datatable(resulttab, extensions = 'Buttons', options = list(
      dom = 'Bfrtip',
      buttons = 
        list('copy', 'print', list(
          extend = 'collection',
          buttons = list(list(extend='csv',
                              filename = 'blBericht'),
                         list(extend='excel',
                              filename = 'blBericht'),
                         list(extend='pdf',
                              filename= 'blBericht')),
          text = 'Download')))) %>%  formatStyle('Tribrommethan',  color = 'red', backgroundColor = 'orange', fontWeight = 'bold')
      })


推荐答案

具有选项excel的数据表的导出按钮显然是一个包装的csv-expo rt。因此格式化无法导出。我的解决方法现在使用Shiny-Export-Button和XLConnect软件包。

The Export-Button of datatables with the option excel is apparently a wrapped csv-export. Thus formatting cannot be exported. My workaround is now using the shiny-Export-Button and the XLConnect package.

我在浏览器中找不到显示工作簿(在downloadHandler中通过XLConnect创建)的解决方案。因此,我将使用renderDataTable函数,而不需要格式化用于浏览器显示,因为在不同的包中定义(众多)格式化条件两次是不可行的。

I couldn't find a solution to display the workbook (created via XLConnect in the downloadHandler) in the browser. Thus I will use a renderDataTable function without formatting for Browser-display, as defining the (numerous) formatting conditions twice in different packages is not viable.

这篇关于R数据表按条件格式化按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆