Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the astra-sites domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/statplace/public_html/site/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the jetpack domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/statplace/public_html/site/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wpforms-lite domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/statplace/public_html/site/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/statplace/public_html/site/wp-includes/functions.php on line 6114

Notice: A função _load_textdomain_just_in_time foi chamada incorretamente. O carregamento da tradução para o domínio astra foi ativado muito cedo. Isso geralmente é um indicador de que algum código no plugin ou tema está sendo executado muito cedo. As traduções devem ser carregadas na ação init ou mais tarde. Leia como Depurar o WordPress para mais informações. (Esta mensagem foi adicionada na versão 6.7.0.) in /home/statplace/public_html/site/wp-includes/functions.php on line 6114
Como usar pacote Data Table no R? - Statplace
artigosdatatable-18

Como usar pacote Data Table no R?

Descubra como usar o pacote Data Table no R para manipular e processar grandes volumes de dados de forma eficiente nas suas análises.

Artigo escrito com a colaboração de Larisse Annie Saldanha

Quando usamos tabelas para as mais diferentes finalidades, podemos criar desde tabelas elaborados no Excel até data frames no R. Mas como deixar essas tabelas mais interativas e fáceis de usar quando estiverem em páginas HTML? É para ajudar nessa tarefa que usamos o pacote data table.

O pacote DT fornece uma interface em JavaScript para a biblioteca DataTable. Os objetos de dados do R (matrizes ou data frames) podem ser exibidos como tabelas em páginas HTML, e o DataTables fornece filtragem, paginação, classificação e muitos outros recursos nas tabelas. Os argumentos são:

datatable(data, options = list(), class = "display",
callback = JS("return table;"), rownames, colnames, container,
caption = NULL, filter = c("none", "bottom", "top"), escape = TRUE,
style = "default", width = NULL, height = NULL, elementId = NULL,
fillContainer = getOption("DT.fillContainer", NULL),
autoHideNavigation = getOption("DT.autoHideNavigation", NULL),
selection = c("multiple", "single", "none"), extensions = list(),
plugins = NULL, editable = FALSE)

Editando Tabelas no data table

Pode-se editar uma tabela via argumento editable do pacote. Depois de finalizar as edições, pode-se obter os índices da coluna e linha e os novos valores das células onde foram editadas via input$tableId_cell_info.

De modo geral, cria-se um observeEvent() da seguinte maneira:

observeEvent(input$table_cell_edit, {
info = input$table_cell_edit
proxy4 = dataTableProxy("table")

str(info)
i = info$row
j = info$col + 1  # column index offset by 1
v = info$value

dados[i, j] <<- DT::coerceValue(v, dados[i, j]) 
replaceData(proxy4, dados , resetPaging = FALSE, rownames = FALSE) })

Algumas Extensões Úteis do pacote data table

AutoFill

Com essa extensão, você verá um quadrado azul no canto direito que te permite preencher toda a coluna ou a linha.

library(DT)
datatable(iris, extensions = c('AutoFill','KeyTable'), editable = TRUE, options = list(
    autoFill = TRUE, keys= TRUE))

Botões

datatable(
  iris, extensions = 'Buttons', options = list(
    dom = 'Bfrtip',
    buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
  )
)

Visibilidade

datatable(
  iris, rownames = FALSE,
  extensions = 'Buttons', options = list(dom = 'Bfrtip', buttons = I('colvis'))
)

KeyTable

datatable(iris, extensions = 'KeyTable', options = list(keys = TRUE))

Painéis de Busca

datatable(
  iris,
  options = list(dom = 'Pfrtip', columnDefs = list(list(
    searchPanes = list(show = FALSE), targets = 1:4
  ))),
  extensions = c('Select', 'SearchPanes'),
  selection = 'none'
)

Você já usa o Data Table para editar as suas tabelas no R? Tem alguma dica extra? Diz pra gente aqui nos comentários. E não esqueça de seguir a Oper nas redes sociais, estamos no Instagram, Facebook e LinkedIn!

Share the Post:
Compartilhar no facebook
Compartilhar no twitter
Compartilhar no linkedin

4 comentários em “Como usar pacote Data Table no R?”

  1. Olá amigo, bom dia!
    Excelente material!!!
    Sabe dizer onde encontro mais material dessa biblioteca Datatable para R? Gostaria de fazer algumas edições nas visualizações, porém só encontro na sintaxe de JS puro. Preciso de mais detalhes desse funcionamento.
    Obrigado

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Related Posts