renderTable passes any extra arguments along to xtable, so I think you should be able to do something like this:
renderTable({
# Code to generate table here
}, digits=4)
It looks like xtable only lets you control the total number of digits, and not the number of digits after the decimal point. If you need finer control, you can use sprintf() to convert it to a string with a specified format. In this example, it converts column x to a string with 3 digits after the decimal point:
df <- data.frame(x=rnorm(10), y=rnorm(10), label=letters[1:10])
df$x <- sprintf('%1.3f', df$x)
If you want to do this to all columns in the data frame, you could do something like this:
# Given a column: if numeric, convert to formatted string; otherwise, return unchanged
format_num <- function(col) {
if (is.numeric(col))
sprintf('%1.3f', col)
else
col
}
# Apply the function to each column, and convert the list output back to a data frame
as.data.frame(lapply(df, format_num))
-Winston