Open kyle-power opened 3 years ago
Similar to the downloadButton
issue https://github.com/Appsilon/shiny.fluent/issues/39
I have implemented a work-around using the following...
## UI Stack Component
Stack(
grow = TRUE,
DefaultButton.shinyInput(
inputId = ns("uploadButton"), text = "Upload File", styles = list(root = list(width = "100%"))
),
tags$input(id = ns("upload"), type = "file", style = "visibility: hidden; height: 0; width: 0; margin: 0;")
)
## Server Event
observeEvent(input$uploadSSIM, {
shinyjs::click("upload")
})
Again, it would be helpful to have a uploadHelper()
function as part of shiny.fluent
. Thanks!
Related issue: Appsilon/shiny.react#11.
Are there any plans to add this? The workaround above does not work for me.
Any progress on file upload?
Hi,
I made custom fileinput UI looks simillar with fluentUI which modified basic shiny's fileInput
below is minimal reproducible example
library(shiny)
library(shiny.fluent)
#>
#> Attaching package: 'shiny.fluent'
#> The following object is masked from 'package:shiny':
#>
#> runExample
fileInput.fluent <- function(inputId, label = 'file', multiple = FALSE, accept = NULL, capture = NULL) {
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(
type = "file",
id = inputId,
name = inputId,
style = "position: absolute !important; top: -99999px !important; left: -99999px !important;",
`data-restore` = restoredValue
)
if (multiple) {
inputTag$attribs$multiple <- "multiple"
}
if (length(accept) > 0) {
inputTag$attribs$accept <- paste(accept, collapse = ",")
}
if (!is.null(capture)) {
inputTag$attribs$capture <- capture
}
tags$label(
icon('upload', style = 'padding-top:7px'),
label,
class = 'fileupload',
inputTag
)
}
ui <- fluentPage(
tags$head( # you may change this in .css file
tags$style(HTML('
.fileupload{
margin-top: auto;
margin-bottom: auto;
outline: transparent;
position: relative;
font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
-webkit-font-smoothing: antialiased;
font-size: 14px;
font-weight: 400;
box-sizing: border-box;
border: 1px solid rgb(0, 120, 212);
display: inline-block;
text-decoration: none;
text-align: center;
cursor: pointer;
padding: 0px 16px;
border-radius: 2px;
min-width: 80px;
height: 32px;
background-color: rgb(0, 120, 212);
color: rgb(255, 255, 255);
user-select: none;
}
.fileupload:hover{
background-color: rgb(16, 110, 190);
border: 1px solid rgb(16, 110, 190);
color: rgb(255, 255, 255);
cursor: pointer;
}'
))
),
fileInput.fluent(inputId = 'file',label = 'file'),
)
server <- function(input, output, session){
observeEvent(input$file,{
print(input$file)
})
}
shinyApp(ui, server)
#>
#> Listening on http://127.0.0.1:6717
Created on 2023-09-13 with reprex v2.0.2
You may change style and icon or label.
Thanks.
Add support for a
shiny.fluent
component that allows users to upload a file; similar toshiny::fileInput()
.