Format columns % using DT

dt

#1

I am picking this example from DT format column documentation directly

library(DT)
m = cbind(matrix(rnorm(60, 1e5, 1e6), 20), runif(20), rnorm(20, 100))
m[, 1:3] = round(m[, 1:3])
m[, 4:5] = round(m[, 4:5], 7)
colnames(m) = head(LETTERS, ncol(m))
head(m)
##            A        B        C         D         E
## [1,] -460476  -967824  -594707 0.6478935  99.50897
## [2,] -130177  -117975  -107917 0.3198206  97.69083
## [3,] 1658708  -926004 -1165396 0.3077200 101.00574
## [4,]  170508  -628891  2268956 0.2197676  99.29080
## [5,]  229288  -525039  1307962 0.3694889  99.31199
## [6,] 1815065 -1586693 -1023109 0.9842192 101.02557
# format the columns A and C as currency, and D as percentages
datatable(m) %>% formatCurrency(c('A', 'C')) %>% formatPercentage('D', 2)

Now here as you see above the value for D are in decimals and then formatted using formatPercentage.

Now I want to use slider inputs so that I can filter the table. But if I use the min max as 20 and 40 respectievly it wont work but it will work when I choose the min max as 0.2 and 0.4 . So my slider range is 0.1 to 0.9 .

 sliderInput("range_value",    
label = h3("Put a range value"),
                         min = 20,
                         max = 40,post  = " %",
                          value = c(20, 40)
                                   )

How can I show the slider range as 10% to 100% with the min and max values being 20 and 40


#2

Hi,

May be you can just divided your slider inputs by 100 in the server part (before using it to filter your data) ?

HTH :slight_smile:

A.D.