简体   繁体   中英

Using formattable in R with dynamic column headers

Formattable allows one make formatted data output in R and Rshiny. A good explanation is here: 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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