Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset does not work for fileInput() when inputId contains a dot "." #140

Closed
thothal opened this issue Aug 8, 2017 · 1 comment
Closed

Comments

@thothal
Copy link

thothal commented Aug 8, 2017

Consider this MRE:

library(shiny)
library(shinyjs)

ui <- fluidPage(
   useShinyjs(),
   fileInput("update.File", "Choose File:"),
   actionButton("cancel", "Cancel"),
   fileInput("updateFile", "Choose File:"),
   actionButton("cancel2", "Cancel")
)

server <- function(input, output, session) {
   observeEvent(input$cancel, reset("update.File")) #won't work
   observeEvent(input$cancel2, reset("updateFile")) #works
}

runApp(shinyApp(ui, server))

The reset for update.File does not work, while it does work for updateFile.

I tested reset with all inputs mentioned in the documentation and the problem with the dot occurs only for fileInput elements:

library(shiny)
library(shinyjs)

elems <- c("textInput", "numericInput", "sliderInput", "selectInput",
     "selectizeInput", "radioButtons", "dateInput", "dateRangeInput",
     "checkboxInput", "checkboxGroupInput", "passwordInput",
     "textAreaInput", "fileInput")

defaults <- list(textInput          = list(label = "Text Label:", value = "start"),
                 numericInput       = list(label = "Numeric Label:", 
                                           value = 5, min = 0, max = 10),
                 sliderInput        = list(label = "Slider Label:", 
                                           min = 0, max = 10, value = 2:6),
                 selectInput        = list(label = "Select Label:", 
                                           choices = paste("Choice", 1:3)),
                 selectizeInput     = list(label = "Selectize Label:", 
                                           choices = paste("Choice", 1:3)),
                 radioButtons       = list(label = "Radio Label:", 
                                           choices = paste("Choice", 1:3)),
                 dateInput          = list(label = "Date Label:", value = "2017-01-06", 
                                           min = "2017-01-01", max = "2018-12-31"),
                 dateRangeInput     = list(label = "Date Range Label:", 
                                           start = "2017-06-01", end = "2017-07-01", 
                                           min = "2017-01-01", max = "2018-12-31"),
                 checkboxInput      = list(label = "Checkbox Label:", value = TRUE),
                 checkboxGroupInput = list(label = "Checkboxgroup Label:", 
                                           choices = paste("Choice", 1:3)),
                 passwordInput      = list(label = "Password Label:", value = "start"),
                 textAreaInput      = list(label = "Text Area Label:", value = "start"),
                 fileInput          = list(label = "File Label:"))

CancelUI <- function(id, el = elems) {
   ns <- NS(id)
   el <- match.arg(el, elems)
   def <- defaults[[el]]
   tagList(h2(el),
           do.call(el, c(def, inputId = ns("Name.With.Dot"))),
           actionButton(ns("cancelDot"), "Cancel Dot"),
           do.call(el, c(def, inputId = ns("NameWithOutDot"))),
           actionButton(ns("cancelNoDot"), "Cancel No Dot"))
}

Cancel <- function(input, output, session) {
   observeEvent(input$cancelDot, reset("Name.With.Dot"))
   observeEvent(input$cancelNoDot, reset("NameWithOutDot"))
}

ui <- fluidPage(useShinyjs(), lapply(elems, function(n) CancelUI(n, n)))

server <- function(input, output, session) {
   handler <- lapply(elems, function(n) callModule(Cancel, n))
}
@daattali
Copy link
Owner

daattali commented Aug 8, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants