3

Trying to make a table in shiny using expss package however while downloading data, HTML tags are also coming in the column headers which should not be.

can anyone please help here.

#install.packages("expss")
library("expss")
library(shiny)
shinyApp(
ui = fluidPage(fluidRow(column(12, dataTableOutput('txt')))),
server = function(input, output) {
  table <- reactive({
  data(mtcars)
  var_text = "vs_sum = vs==0, am_sum = am==1, gear_sum = gear == 4|gear==5, carb_sum = total(carb)"
  var_expr = parse(text = sprintf("data.frame(%s)", var_text)) # parse text string to expression

  var_list = calc(mtcars, 1*eval(var_expr)) %>% # caclulate data.frame with zero/one columns
    prepend_names() %>% # add names as labels
    mis_val(0) %>% # we don't need columns with FALSE condition
    set_val_lab(c("|" = 1)) # suppress values in table - we don't want to see TRUE/1

  mtcars %>%
    tab_prepend_values %>%
    tab_cols(total(), var_list) %>%
    tab_cells(cyl) %>%
    tab_stat_cpct() %>%
    tab_pivot()      
})


output$txt <- renderDataTable({
  as.datatable_widget(table(), rownames = F,filter = 'top', extensions = "Buttons",
                      options = list(
                        dom = 'Bfrtip',
                        scrollX = TRUE,
                        columnDefs = list(list(className = 'dt-center', targets = "_all")),
                        buttons = list(
                          'colvis',
                          list(
                            extend = 'collection',
                            buttons = c('csv', 'excel', 'pdf'),
                            text = 'Download'
                          )
                        )
                      ))
}, server = F)

} )

while downloading the output th { text-align:center; } th{border: 1px solid #DDD appears with column header, what am i missing here. could you please suggestenter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
nikki
  • 239
  • 1
  • 12
  • 2
    It seems there is a conflict between custom header inside as.datatable_widget and Excel export facility. Try `split_columns(table())` - it will convert table to usual data.frame. – Gregory Demin Jun 13 '18 at 11:56
  • hey Gregory, is there a way such that we can print cyl as a question text in each row of our output instead of first line. – nikki Jun 21 '18 at 08:38
  • Yes: split_columns(table(), remove_repeated = FALSE) – Gregory Demin Jun 21 '18 at 17:38

0 Answers0