For this post, we need to load the following library:
For this post, we’ll use a dataset with different data types such as integer, numeric, factor, logical, and character.
By default, DT tables have no
filters. However, the
datatable() function has a
filter argument with very useful properties, depending on
the type of data.
Integer and numeric columns have range sliders, while other variables have a choice of all possible values.
Keep in mind: make sure your variables have the right type so that the filters match. You may need to manually change the type of some of your columns.
The cells can be edited directly into the table by double clicking on it, changing the value and then clicking outside. It’s also possible to make only specific as editable.
In the case you want all cells to be editable, put
editable='cell' in the
Otherwise, put a list in argument of the
like in the example below that allows editing in column 1, 3 and 5, for
Here’s what the output looks like when we put all together the features we’ve seen before:
df = rbind(df, df, df) # add more rows table = datatable(df, editable = list(target = 'row', disable = list(columns = c(1, 3, 5))), caption = tags$caption(style = 'caption-side: bottom; text-align: center;', 'Table 1: ', em('This is a legend that you can customize')), filter = 'top') # save widget library(htmltools) saveWidget(table, file="HtmlWidget/dt-all-features.html")