How to show values in hidden columns for 'datatable' (R) in a correct format?

There is an extension for "datatables" in R called "Responsive". It adds the "green plus" button on the left side of the row. By clicking on it we can get the view with "hidden" columns.

Here is an example. The "visible" column "mpg_percents_visible" has correct format (3%) when "hidden" column "mpg_percents_hidden" has incorrect formatting in extended view (0.0326644890340644).

library(DT)

# 1. Data set
df_mtcars <- mtcars %>% 
  mutate(
    mpg_percents_visible = mpg / sum(mpg),
    mpg_percents_hidden = mpg / sum(mpg)) %>% 
  select(mpg_percents_visible, everything())

# 2. Datatable
datatable(df_mtcars, extensions = c('Responsive')) %>% 
  formatPercentage(c('mpg_percents_visible', 'mpg_percents_hidden'))

How to show hidden column "mpg_percents_hidden" in a correct format (3%)?

Thanks!

Might be a known bug

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.