Displaying datatable column values in dollars in Shiny r

独自空忆成欢 提交于 2020-02-02 10:14:27

问题


I have a datatable where one of the columns should be expressed in dollars and some as percentages. I've been looking around and I'm still not sure how to do it - seems like it would be easy?

The trickier part is I have another data table where only certain entries need to be expressed as dollars (i.e. not whole rows or whole columns) - is there a way to handle this?


回答1:


Imagine your datatable (myData) is 2 columns by 10 rows.

You want the second row to be in dollars:

myData[,2]<-sapply(myData[,2],function(x) paste0("$",x))

Or, you want rows 6 to 10 in the first column to be percentages:

myData[6:10,1]<-sapply(myData[6:10,1],function(x) paste0(x,"%"))

Or, you want rows 1 to 5 in the second column to be in dollars, you can do:

myData[1:5,2]<-sapply(myData[1:5,2],function(x) paste0("$",x))


来源:https://stackoverflow.com/questions/28033941/displaying-datatable-column-values-in-dollars-in-shiny-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!