Datatable Extension Responsive not does not work

Hello everyone can you tell me why my datatable , Extension "responsive" does not work with some condition data,, here the explanation..

library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(
    Input: Select number of rows to display ----
      radioButtons("disp", "Show Data",
                   choices = c(Head = "head",
                               Setosa = "setosa",
                               Versicolor = "versicolor",
                               All = "All"
                   ),
                   selected = "head"),
    DTOutput('tbl')),
  server = function(input, output) {
    if(input$disp == "head") {
      return(head(iris))
    }else if(input$disp == "setosa"){
      return(iris[iris$Species == input$disp,])
    }else if(input$disp == "versicolor"){
      return(iris[iris$Species == input$disp,])
    }
    else {
      return(iris)
    }
    output$tbl = renderDT(
      DT::datatable(
        iris,extensions = 'Responsive'
      )
    )
  }
)

Datatable still showing the data but "Responsive" does not work ...
this is example with "iris" my real data have more column that iris have...
Thanks

Thank you for the reprex! Updating your example...

library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(
    # "Input: Select number of rows to display ----",
    radioButtons(
      "disp", "Show Data",
      choices = c(
        Head = "head",
        Setosa = "setosa",
        Versicolor = "versicolor",
        All = "All"
      ),
      selected = "head"),
    DTOutput('tbl')
  ),
  server = function(input, output) {

    dt <- reactive({
      if(input$disp == "head") {
        return(head(iris))
      }else if(input$disp == "setosa"){
        return(iris[iris$Species == input$disp,])
      }else if(input$disp == "versicolor"){
        return(iris[iris$Species == input$disp,])
      }
      else {
        return(iris)
      }
    })

    output$tbl <- renderDT({
      DT::datatable(
        dt(),extensions = 'Responsive'
      )
    })
  }
)

For documentation... The Responsive extension is meant to tell the DT table to resize when the window resizes. https://rstudio.github.io/DT/extensions.html#responsive

Please let me know if the updated app did not fix your issue!

- Barret

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