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() cannot clear dates #100

Closed
Avatoo opened this issue Nov 22, 2016 · 7 comments
Closed

reset() cannot clear dates #100

Avatoo opened this issue Nov 22, 2016 · 7 comments

Comments

@Avatoo
Copy link

Avatoo commented Nov 22, 2016

I'm writing an app where a few date inputs are required to be reset i.e. being blank after a cancel button. I really like the shinyjs::reset() function with which a whole page can go back to default when id takes the id of a
tabsetPanel. However, it doesn't seem to work with date inputs yet. Date resetting via updateDateInput() has been fixed since shiny version 0.14 though.

Below is an example adapted from (shiny issue #1317).

library(shiny)
library(shinyjs)

shinyApp(
  ui = fluidPage(
    useShinyjs(),
    div(
      dateInput("date", "Date", min = "2014-06-10", value = NA)
    ),
    actionButton("btn1", "reset date NA"),
    actionButton("btn2", "reset date NULL"),
    actionButton("btn3", "reset date using shinyjs::reset"),
    hr(),
    div(
      textInput("text", "Text", value = "")
      # test if shinyjs::reset clears text input
    ),
    actionButton("btn4", "reset text")    
  ),
  server = function(input, output, session) {
    observeEvent(input$btn1, updateDateInput(session, "date", value = NA))
    observeEvent(input$btn2, updateDateInput(session, "date", value = NULL))
    observeEvent(input$btn3, reset("date"))
    observeEvent(input$btn4, reset("text"))
  }
)
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 10 x64 (build 10586)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shinyjs_0.8.0.9001 shiny_0.14.2.9000 

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.5       digest_0.6.10     withr_1.0.2       mime_0.5          R6_2.2.0         
 [6] jsonlite_1.1.9000 xtable_1.8-2      git2r_0.15.0      httr_1.2.0        curl_0.9.7       
[11] miniUI_0.1.1      devtools_1.12.0   tools_3.3.1       httpuv_1.3.3      memoise_1.0.0    
[16] htmltools_0.3.5   knitr_1.13 
@daattali
Copy link
Owner

Hi

I haven't tried running your code, but to the best of my knowledge, the
reset function has always worked on date inputs. From a quick look at your
code, it looks like you forgot to include the call to "useShinyjs()" in
your UI. I think if you'll add that, you'll see the reset function working


R-Shiny Consultant
http://deanattali.com/shiny

On 22 November 2016 at 18:42, Avatoo [email protected] wrote:

I'm writing an app where a few date inputs are required to be reset i.e.
being blank after a cancel button. I really like the shinyjs::reset()
function with which a whole page can go back to default when id takes the
id of a
tabsetPanel. However, it doesn't seem to work with date inputs yet. Date
resetting via updateDateInput() has been fixed since shiny version 0.14
though.

Below is an example adapted from (shiny issue #1317
rstudio/shiny#1317).

library(shiny)
library(shinyjs)

shinyApp(
ui = fluidPage(
div(
dateInput("date", "Date", min = "2014-06-10")
),
actionButton("btn1", "reset date NA"),
actionButton("btn2", "reset date NULL"),
actionButton("btn3", "reset date using shinyjs::reset")
),
server = function(input, output, session) {
observeEvent(input$btn1, updateDateInput(session, "date", value = NA))
observeEvent(input$btn2, updateDateInput(session, "date", value = NULL))
observeEvent(input$btn3, reset("date"))
}
)

sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 10 x64 (build 10586)

locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] shinyjs_0.8.0.9001 shiny_0.14.2.9000

loaded via a namespace (and not attached):
[1] Rcpp_0.12.5 digest_0.6.10 withr_1.0.2 mime_0.5 R6_2.2.0
[6] jsonlite_1.1.9000 xtable_1.8-2 git2r_0.15.0 httr_1.2.0 curl_0.9.7
[11] miniUI_0.1.1 devtools_1.12.0 tools_3.3.1 httpuv_1.3.3 memoise_1.0.0
[16] htmltools_0.3.5 knitr_1.13


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#100, or mute the thread
https://github.com/notifications/unsubscribe-auth/AA6IFEqgcv2JfTJJcSja5fYFOKbivuVYks5rA33agaJpZM4K6E0s
.

@Avatoo
Copy link
Author

Avatoo commented Nov 23, 2016

Hi Dean,

Thanks for the quick reply. I updated the above example to include useShinyjs() and a textInput widget to test if reset() works at all. reset() clears the date to be "today" but I would like the value to go blank, as the first button behaves. Make sense?

Ava

@daattali
Copy link
Owner

That's not what the reset function does though. If you look at the documentation for shinyjs::reset(), its job is to reset the value of an input back to its original value. What you are referring to is what I would call "clear", not "reset", and that's not a functionality that shinyjs has because it hasn't been requested by many people (you're the first person I see that asks for this, whereas resetting is something I've seen people ask about many many times)

I'm closing this issue since reset does work as it should

@Avatoo
Copy link
Author

Avatoo commented Nov 23, 2016

In the example, my original value is empty by setting the value argument of dateInput() to NA. The document of updateDateInput() says it "Supply NA to clear the date".

The reason for not setting original value to NULL, i.e. today, is that some action may happen in a future date. The user may prefer not to fill in the field for the time being, but come back to edit it when available.

P.S. I removed a comment after second edit. Sorry if that led to confuse.

@daattali
Copy link
Owner

Oh I understand. I apologize, in that case that really is something that shinyjs::reset should support.

@daattali daattali reopened this Nov 23, 2016
@daattali
Copy link
Owner

This should be solved now

@Avatoo
Copy link
Author

Avatoo commented Nov 23, 2016

Thanks very much. It works in my production app now.

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