I successfully minimized the fileInput function by removing the upload area and loading bar, giving it a similar appearance to a downloadButton. However, I'm facing difficulties in determining which part of the CSS code needs to be modified to make it behave like a download button when the window is resized. Any assistance on this matter would be greatly appreciated.
Image display with wide sidebarPanel:
https://i.sstatic.net/GEgCT.png
Image display with narrow sidebarPanel:
https://i.sstatic.net/7Cs3R.png
Below is the code snippet including the parts that were commented out in my adjusted fileInput for future reference:
library(shiny)
fileInputNoExtra<-function(inputId, label, multiple = FALSE, accept = NULL, width = NULL, buttonLabel = "Browse...", placeholder = "No file selected"){
restoredValue <- restoreInput(id = inputId, default = NULL)
if (!is.null(restoredValue) && !is.data.frame(restoredValue)) {
warning("Restored value for ", inputId, " has incorrect format.")
restoredValue <- NULL
}
if (!is.null(restoredValue)) {
restoredValue <- toJSON(restoredValue, strict_atomic = FALSE)
}
inputTag <- tags$input(id = inputId, name = inputId, type = "file",
style = "display: none;",
`data-restore` = restoredValue)
if (multiple)
inputTag$attribs$multiple <- "multiple"
if (length(accept) > 0)
inputTag$attribs$accept <- paste(accept, collapse = ",")
# div(class = "form-group shiny-input-container", style = if (!is.null(width))
# paste0("width: ", validateCssUnit(width), ";"), #label %AND%
# tags$label(label),
#div(class = "input-group",
tags$label(class = "input-group-btn", type="button", style=if (!is.null(width)) paste0("width: ", validateCssUnit(width),";","padding-right: 5px; padding-bottom: 5px;"),
span(class = "btn btn-default btn-file",type="button", buttonLabel, inputTag, style=if (!is.null(width)) paste0("width: ", validateCssUnit(width),";","border-radius: 5px; padding-bottom: 5px;"))
)#,
#tags$label(class = "input-group-btn", type="button", span(class = "btn btn-default", buttonLabel, inputTag))#,
#tags$input(type = "text", class = "form-control", placeholder = placeholder, readonly = "readonly")
#)
# tags$div(id = paste(inputId, "_progress", sep = ""), class = "progress progress-striped active shiny-file-input-progress", tags$div(class = "progress-bar"))
# )
}
ui <- fluidPage(sidebarLayout(
sidebarPanel(
fileInputNoExtra("test1",label="",accept=".lmmm",buttonLabel=list(icon("folder"),"Normal upload button1"),width="200px"),
fileInputNoExtra("test2",label="",accept=".lmmm",buttonLabel=list(icon("folder"),"Normal upload button2"),width="200px"),
downloadButton("test3",label="Normal download button3"),
downloadButton("test4",label="Normal download button4")
),
mainPanel()
))
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)