-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Added dismissalert to remove arbitrary number of messages #30
Conversation
Changes:
I added myself to DESCRIPTION as |
@@ -253,10 +265,34 @@ shinyalert <- function( | |||
} | |||
}, once = TRUE) | |||
params[['callbackR']] <- NULL | |||
} else { | |||
# Still create `cbid` used by closeAlert to explicitly close this alert |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the if statement I added a comment that the serialization isn't happening to prevent a performance issue #19
Did you notice that and test if this change is going to re-introduce that issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't recommend params <- as.list(environment())
at the very beginning. Chances are too small for two alerts sharing the same cbid with runif
postfix. If you get rid of the enclosing environment, digest::digest
will be quite fast as everything else should be basic types and contain no environment. Alternatively you could use utils::capture.output({print(environment())})
to distinguish environments because the runtime environment of R functions will unlikely to be named, meaning its memory address will be printed, resulting in something like "<environment: 0x7f802d60a1b0>"
. Serializing string is much faster than serializing an environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, if you do want to keep params <- as.list(environment())
, you can create random cbid
with no digests for alerts without callbacks. The returned cbid
can be used to close that specific alert or writers can use that cbid
to generate their own callbacks outside of shinyalert
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line params <- as.list(environment())
is not for serialization or creating a unique ID, it was simply a way to get a list of all the function arguments values - default values for arguments that weren't provided and the user-supplied values for the arguments that were provided. Do you know of an alternative way to get all the arguments of the current function as a list?
But anyway, you're right that the digest isn't actually required , it was only to add some randomness. Instead of using the params hash plus a random integer, it might be better to just use the uuid
package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that way you are right, but your function arguments contains no function except callbackR
, which will be removed before serialization. Therefore serialization should be fast. Also personally I think using runif
is good enough to create unique IDs unless people set seed before calling the function. In that case, you might want to consider utils::capture.output({print(environment())})
I proposed to ensure different IDs created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the great PR!
I apologize for being so picky but I do have a few things I would ask of you before merging:
- Remove all changes that are not directly related to closeAlert
- Files should end with a newline
- The
immediate
parameter is related but not should not go in the same PR ascloseAlert
- It looks like some of the code (to create the callback id) can be reused instead of being used twice identically
- I don't see the use for the
n
argument in closeAlert. It seems very esoteric - what's the use case for that? I would prefer to just have cbid argument and if none is provided then you close everything
// Always create cbid | ||
var cbid = params['cbid']; | ||
delete params['cbid']; | ||
if(typeof cbid === 'string'){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is cbid not alwasy going to be a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove the if
statement if you always include cbid
in R code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't before, but my understanding is that your PR ensures that cbid
is ALWAYS going to be in the javascript parameters, in which case this check is redundant. Is that right?
callbackR = function(value) { | ||
Shiny.onInputChange(cbid, value); | ||
} | ||
} | ||
|
||
var callback = function(value) { | ||
// Remove instance immediately | ||
var ii = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a better variable name
I made a commit that uses |
@dipterix let me know if you plan on continuing this or if I should take over! |
I got fever. Please go ahead make changes if you feel necessary. |
I'm working on some other packages this week, if you don't finish the PR by the end of the month I'll try to finish it :) |
@dipterix Are you able to finish this PR? |
I actually went through all your code and I'm mostly done integrating it. I might ask you for a PR soon :) |
Hi @daattali , sorry for the late reply. The conflicts have been resolved. |
Merged in #37 |
This PR is related to issue #29
A simple demo showing how it works: