Shiny customise fileInput

血红的双手。 提交于 2021-01-28 05:46:26

问题


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

This is how it currently is:

and this is how I want it to be:


回答1:


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)


来源:https://stackoverflow.com/questions/49506469/shiny-customise-fileinput

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!