R shiny - DT :: renderDataTable column width

I make the application brilliant and run into a small but annoying problem. Part of the result I output is output using DT::renderDataTable . There are only two columns, and the width of the first column will depend on the input dataset, so I don’t want to absolutely fix the width on anything. I saw this thread, and the code in one of the answers works to some extent. However, if I pulled out an actionButton a second time, the table will resize to fill the entire width of the output window.

Is there a way to prevent the table from resizing after clicking the action button again? I know that using only renderTable and tableOutput will solve the problem, but I like dataTableOutput and I would rather use this function.

For MWE:

 library("shiny") library("DT") mwe_ui <- shinyUI(fluidPage( sidebarLayout( sidebarPanel( titlePanel("Example"), sliderInput(inputId = "df", label = "Degrees of Freedom:", min=1 , max=50 , value=1 , step=1 ), actionButton(inputId = "compute1", label = "Sample" ) ), mainPanel( dataTableOutput( outputId = "summary" ) ) ))) mwe_server <- function(input, output) { temp01 <- reactive({ compute1 <- input$compute1 if( compute1 > 0 ){ isolate({ aa <- round( runif(6, 4,20 ) ) bb <- character() for( ii in 1:6 ){ bb[ii] <- paste0(sample(letters, size=aa[ii]), collapse="") } xx <- matrix( round(rt(6, df=input$df), 4), nrow=6, ncol=1 ) return( data.frame(xx) ) }) } }) ############## output$summary <- DT::renderDataTable({ temp02 <- temp01() }, rownames=FALSE, options = list(autoWidth = TRUE, columnDefs = list(list(width = "125px", targets = "_all")) ) ) } runApp( list(ui=mwe_ui, server=mwe_server) ) 
+5
source share

Source: https://habr.com/ru/post/1232994/


All Articles