简体   繁体   English

在R中使用带有动态列标题的formattable

[英]Using formattable in R with dynamic column headers

Formattable allows one make formatted data output in R and Rshiny. Formattable允许在R和Rshiny中输出一个make格式化数据。 A good explanation is here: https://www.r-bloggers.com/formatting-table-output-in-r/ 一个很好的解释在这里: https : //www.r-bloggers.com/formatting-table-output-in-r/

示例代码

In the "formatter" function above you can see that the column headers are referenced. 在上面的“格式化程序”功能中,您可以看到已引用了列标​​题。 I would like to know if this code can be written in a way as to work with dynamic column headers that change based on a users input to an rshiny app. 我想知道此代码是否可以以与根据用户输入rshiny应用程序的输入而变化的动态列标题一起使用的方式编写。 I was thinking that there may be a way to reference the column number instead of the specific name but I have been unsuccessful at doing this thus far. 我以为可能有一种方法可以引用列号而不是特定的名称,但是到目前为止,我这样做仍然没有成功。 Any help is appreciated. 任何帮助表示赞赏。

Thanks. 谢谢。

It appears that the function is looking for a named list to match up to the names in the data.frame. 似乎该函数正在寻找一个命名列表,以匹配data.frame中的名称。 I recommend that you create the list with your desired formats, then set the name(s) of the format arguments "dynamically" to match what you are displaying. 我建议您使用所需的格式创建列表,然后“动态”设置格式参数的名称以匹配您要显示的内容。

eg: 例如:

myFormats <- list( formatter("span") )
names(myFormats) <- input$userEnteredChoiceHere

formattable(DF, myFormats)

Without actually reproducible code though, it is hard to help you more than that. 但是,如果没有实际可复制的代码,很难为您提供更多帮助。 A picture of code is not easy to work from. 代码的图片并不容易使用。

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

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