Make datatable take up entire page r shiny

32 views Asked by At

I have a shiny app. I want to make my datatable take up the entire page of my tab. Here is what it looks like now. I want to make it so that the table takes up more space on the page. I understand if the window is smaller that you may need to scroll, but I would just like the table taking up the entire space on the page in the first place. How can I do this? I am new to r shiny, so I am providing my entire ui because I cannot seem to find a solution that makes sense online for the ui part, but only the server part which pertains to this tab and table. Ideally, I would also like to have the headers for the columns centered. I also don't understand why when I rename the columns and use "\n" that it is not moving the text to the next row for the headers.

enter image description here

ui<- navbarPage(
  title = "Quinn MU Habitat, Demographic, Genetic, and Climate Data",
  tabPanel(
    "Remote Sensing Data",
    sidebarLayout(
      sidebarPanel(
        # Dropdown menu to select polygon layer
        selectInput("layer", "Select remote sensing product:",
                    choices = c("NDVI status" = "Polygon Layer 1",
                                "NDVI trend 1985-2021" = "Polygon Layer 2",
                                "NDVI trend 2017-2021" = "Polygon Layer 3",
                                "NDVI resilience 2017-2021" = "Polygon Layer 4",
                                "Percentage Active Riparian" = "Polygon Layer 5",
                                "Valley Bottom Area (sqkm)" = "Polygon Layer 6"),
                    selected = "NDVI status"),
        # Dropdown menu to select group
        selectInput("Pop_Name", "Select population:",
                    choices = c("Andorno Creek", "Battle Creek",
                                "Colman Creek",
                                "Crowley Creek", "Eightmile Creek",
                                "Falls Canyon Creek", "Jackson Creek",
                                "Sage Line and Corral Creeks",
                                "Threemile Creek",
                                "Washburn Creek"),
                    selected = "Andorno Creek"),
        # Panel for distribution plot
        plotOutput("distributionPlot")
      ),
      mainPanel(
        leafletOutput("map"),  # Output to render the leaflet map
        verbatimTextOutput("layerDescription")  # Output to display layer description
      )
    )
  ),
  tabPanel(
    "Demographic Data",
    sidebarLayout(
      sidebarPanel(
        # Dropdown menu to select time series dataset
        selectInput("dataset", "Select time series dataset:",
                    choices = c("Abundance (LCT >120mm)"="Dataset 1", 
                                "Length-frequency"="Dataset 2", 
                                "Dataset 3"),
                    selected = "Dataset 1"),
        # Dropdown menu to select population within the time series
        selectInput("Pop_Name_TS", "Select population:",
                    choices = c("Andorno Creek", "Battle Creek",
                                "Colman Creek",
                                "Crowley Creek", "Eightmile Creek",
                                "Falls Canyon Creek", "Jackson Creek",
                                "Sage Line and Corral Creeks",
                                "Threemile Creek",
                                "Washburn Creek"),
                    selected = "Andorno Creek"),
        # Panel for time series plot
        plotOutput("timeSeriesPlot")
      ),
      mainPanel(
        # Placeholder for additional content in the main panel
              )
    )
  ),
  tabPanel(
    "Genetic Data",
          mainPanel(
            fluidRow(
              column(width = 10, 
                     dataTableOutput("demoGenTable")))
      )
    ),
  tabPanel(
    "Climate Data",
    sidebarLayout(
      sidebarPanel(
        # Dropdown menu to select climate dataset
        selectInput("climate_dataset", "Select climate dataset:",
                    choices = c("Average Air Temp (Deg F)"="Climate Dataset 1", 
              "Snow water equivalent (in) @ Disaster Peak Snotel"="Climate Dataset 2",
              "Maximum Air Temp Deg F"="Climate Dataset 3",
              "McDermitt Creek Discharge April(cubic meters/sec)"="Climate Dataset 4",
              "McDermitt Creek Discharge August(cubic meters/sec)"="Climate Dataset 5",
              "Quinn River Discharge April (cubic meters/sec)"="Climate Dataset 6",
              "Quinn River Discharge August (cubic meters/sec)"="Climate Dataset 7"),
                    selected = "Climate Dataset 1")),
        # Panel for climate data plot
      #   plotOutput("climateTimeSeries")
      # ),
      mainPanel(
        plotOutput("climateTimeSeries",height="600px")# Placeholder for additional content in the main panel
      )
    )
  )
)

server<-function(input, output) {
###Genetics table####
  # Render the demographic and genetic data table
  output$demoGenTable <- renderDataTable({
    # Assuming demoGenData is your data frame
    datatable(genetics, options = list(scrollX=T,
                                       autoWidth = T,
                                       dom = 't', 
                                       paging = F, 
                                       ordering = FALSE,
                                  columnDefs =list(
                                    list(width = '150px', 
                                            targets = c(1:10)))),
              width = "100%",
                                       colnames = c("Population",
                              "Effective pop size\n(Sample size)",
                              "Effective pop size\n(Neville 2022)",
                          "Effective pop size score\n(5-yr review)",
                          "Genetic diversity (He)",
                          "Observed Ho",
                          "Diversity score\n(5-yr review)",
                          "%LCT Hybridization Status\n(year)",
                          "%LCT Hybridization Status\n(Peacock data)",
                          "Hybrid score\n(5-yr review)")
    )

  })


0

There are 0 answers