1
votes

Is there a way to remove text field from fileInput in shiny?

This is how it currently is:

enter image description here

and this is how I want it to be:

enter image description here

1

1 Answers

2
votes

One can define a custom input function, that takes the regular one and cuts away the pieces you don't want.

library(shiny)

fileInputOnlyButton <- function(..., label="") {
  temp <- fileInput(..., label=label)
  # Cut away the label
  temp$children[[1]] <- NULL
  # Cut away the input field (after label is cut, this is position 1 now)
  temp$children[[1]]$children[[2]] <- NULL
  # Remove input group classes (makes button flat on one side)
  temp$children[[1]]$attribs$class <- NULL
  temp$children[[1]]$children[[1]]$attribs$class <- NULL
  temp
}

ui <- shinyUI(fluidPage(
  # Set width to fit the upload progress bar to button size.
  fileInputOnlyButton("file", buttonLabel="Browse", width=72)
))

server <- shinyServer(function(input, output) {})

shinyApp(ui, server)