R shiny - DT::renderDataTable column width

后端 未结 1 1857
春和景丽
春和景丽 2021-01-18 18:07

I\'m making an app in shiny, and have run into a small but irritating problem. Part of the output that I produce is outputted using DT::renderDataTable. There a

相关标签:
1条回答
  • 2021-01-18 18:50

    You could just add the width argument in the ui function instead of inside the columnDefs of the server?

    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" , width="125px")
        )
      )))
    
    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)
      ) 
    }
    
    runApp( list(ui=mwe_ui, server=mwe_server) )
    
    0 讨论(0)
提交回复
热议问题