rstudio / rstudio/bslib

Shiny's reset of file input's `value` interferes with default behaviour

Open
#693 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
SCSS
Stars
569
Forks
72
Avg merge
1d 2h
Merged PRs (30d)
5

Description

Shiny's fileInput() is made up of a number of different elements. Importantly, an uploaded file name is displayed in an element other than the actual file input. As part of the file input binding, Shiny resets the value of the file input element. As stated here, https://github.com/rstudio/shiny/blob/6fc06281bdfea3d2afa5582119469f15d2eed5fc/srcts/src/file/fileProcessor.ts#L246-L248, this allows uploading of the same file multiple times.

When working with the latest file input Bootstrap component I noticed the resetting of a file input's value interferes with the default displaying of an uploaded file's name. The uploaded file's name may be displayed very briefly before the value is reset and then the default text (typically "No file selected") is shown again.

I'm hoping as part of bslib's file input revamp the developer might be able to use a file input element as is.

A small demo,

library(shiny)
library(bslib)

shinyApp(
  ui = page(
    fileInput("demo1", label = "Label"),
    tags$input(type = "file"), # demo2, no id to avoid shiny's file input binding logic
    tags$input(type = "file", id = "demo3")
  ),
  server = function(input, output, session) {
  }
)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the supplied Shiny and bslib demo, comparing demo1 with the unbound demo2 and demo3 inputs. Read the referenced Shiny srcts/src/file/fileProcessor.ts lines and the bslib file-input revamp; done means the uploaded filename remains visible while repeated uploads of the same file still work.

Written by the indexing model from the issue text.

Assessment

Tech stack
bootstrap, r
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.