我目前在尝试从renderTable格式化数据表中的列时遇到困难。正在从我定义的数据帧呈现该表。然后,使用用户输入和子集筛选该数据帧,以形成实现输出时显示的数据帧。有没有一种简单的方法可以将会计/货币格式应用于数据表输出的一列?我在下面添加了代码以供参考:
用户界面:
tableOutput("datetest")
服务器:
df6 <- data.frame(Account_Num,Account_Num_Spec,Account_Name,Billing_Num,Date,Tran_Type,Transaction_Amt2,Bar_Date, Bar_Month,Trannn)
df6_subset <- reactive({
# # Filter Data By Type "Billed" that need to still be paid
df6$Date <- as.Date(df6$Date, "%m/%d/%Y")
filter1_data <- subset(df6, Tran_Type == "Bill")
# Function to filter between 2 Dates
d <- format(as.Date(input$DI))
d1 <- format(as.Date(as.character(input$DI)) - 60)
d2 <- format(as.Date(as.character(input$DI)) - 30)
filter2_data <- filter1_data[filter1_data$Date >= d1 & filter1_data$Date <= d2,]
filter3_data <- na.omit(filter2_data)
filter4_data <- filter3_data[filter3_data$Billing_Num %in% hold,]
filter5_data <- subset(filter4_data,select = -c(Tran_Type,Bar_Date,Date,Bar_Month,Trannn))
return(filter5_data)
})
output$datetest <- renderTable(df6_subset(), spacing=c("xs"), align = NULL)
假设您正在使用dollar_format()
创建自定义货币格式函数
Foodollar <- scales::dollar_format(negative_parens = TRUE, prefix = "*@*")
set.seed(49) #just for reproducability
df <- data.frame(Let = LETTERS[1:10], Money=rnorm(10, 1000, 150))
df
# Let Money
#1 A 948.5101
#2 B 907.9918
#3 C 746.9616
#4 D 908.0822
#5 E 1011.4537
#6 F 902.0824
#7 G 828.3860
#8 H 1328.9407
#9 I 1059.6365
#10 J 990.0883
df$Money <- Foodollar(df$Money)
df
# Let Money
#1 A *@*948.51
#2 B *@*907.99
#3 C *@*746.96
#4 D *@*908.08
#5 E *@*1,011.45
#6 F *@*902.08
#7 G *@*828.39
#8 H *@*1,328.94
#9 I *@*1,059.64
#10 J *@*990.09
这会将df$Money
向量从双精度向量转换为具有Foodollar
指定格式的字符向量
换句话说,我们使用dollar_format
创建函数,然后使用该函数重新定义我们想要的列。