Selection event not fired
sgvignali opened this issue · 4 comments
Hi,
first of all thank you for this package! It looks like the selection event is not fired.
To easily test it you can:
- run
shinyFilesExample()
- add
$('#save').on('selection', function(event, path) {console.log(path);})
form the console of the browser - interact with the button.
I've tried only with shinySaveButton
but I don't know if this happens also with the other buttons.
@sgvignali: I'm not seeing any issues with shinyFiles::shinyFilesExample()
. Can you provide a small fully reproducible example that highlights the issue you are seeing?
Here is a reproducible example:
library(shiny)
library(shinyFiles)
library(shinyjs)
library(fs)
ui <- fluidPage(
useShinyjs(),
headerPanel("Basic example"),
sidebarLayout(
sidebarPanel(
shinyFilesButton(id = "file",
label = "File select",
title = "Please select a file",
multiple = FALSE,
viewtype = "detail"),
tags$hr(),
shinySaveButton(id = "save",
label = "Save file",
title = "Save file as...",
filetype = list(text = "txt"),
viewtype = "icon"),
),
mainPanel(
h4(id = "filetext"),
tags$hr(),
h4(id = "savetext"),
)
)
)
server <- function(input, output, session) {
volumes <- c(Home = fs::path_home())
shinyFileChoose(input,
id = "file",
roots = volumes,
session = session)
shinyFileSave(input,
"save",
roots = volumes,
session = session)
shinyjs::runjs(
"$('#file').on('selection', function(event, path)
{$('#filetext').text('File event fired');})"
)
shinyjs::runjs(
"$('#save').on('selection', function(event, path)
{$('#savetext').text('Save event fired!');})"
)
}
shinyApp(ui = ui, server = server)
When you select a file the selection event is fired and the corresponding h4 tag is populated. This doesn't happen with the save button. I hope this helps!
Sergio
Thanks for that @sgvignali. This my busiest teaching quarter so it will be at least a few weeks before I will be able to make time to work on this. If you want to craft a PR that addresses your concern that would be wonderful