1
votes

It looks like there is an extra space between fileInput and checkboxInput in Shiny (even though I do not add an extra line). How do I get rid of that extra line? Thanks!

if (interactive()) {

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      fileInput("file1", "Choose CSV File",
        accept = c(
          "text/csv",
          "text/comma-separated-values,text/plain",
          ".csv")
        ),
      checkboxInput("header", "Header", TRUE)
    ),
    mainPanel(
      tableOutput("contents")
    )
  )
)

server <- function(input, output) {
  output$contents <- renderTable({
    inFile <- input$file1    
    if (is.null(inFile))
      return(NULL)    
    read.csv(inFile$datapath, header = input$header)
  })
}

shinyApp(ui, server)
}
1

1 Answers

0
votes

Well, this is the space for the progress bar. You can remove the margins of the surrounding elements with CSS, by loading package shinyjs and inserting this anywhere in your UI:

inlineCSS(list(".shiny-input-container" = "margin-bottom: 0px", 
               "#file1_progress" = "margin-bottom: 0px", 
               ".checkbox" = "margin-top: 0px"))

or, if you want to do native CSS without extra package:

      tags$style(".shiny-input-container {margin-bottom: 0px} #file1_progress { margin-bottom: 0px } .checkbox { margin-top: 0px}"),

Tipp: right-click on the space you want to remove and choose "Inspect element". You then see to which node of the HTML the space belongs.

enter image description here