-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Any simple clean way to attach info to a session? #1512
Comments
Sorry, I've been busier than usual the last few weeks. This is an important capability (we've needed it ourselves a couple of times recently) and so easy to add. I'm envisioning |
For my specific case a regular environment is good enough, but I would think making it reactiveValues would be useful. I'd vote for the latter. This wouldn't be backwards compatible though - for older shiny versions, would attaching an attribute to |
@daattali Huh, does attaching an attribute work? If so, that's a fine hack. 👍 |
Yup, you can't Wanted to see if you had any reason to discourage me from doing that. I got your thumbs up though so I'm happy |
I like the idea of having this explicitly as a session element. It seems handy. However, I think I'm missing why exactly this isn't possible as of now without tacking an attribute onto the session object. The scoping rules for shiny: # shared across all sessions
a <- "all"
ui <- fluidPage()
server <- function(input, output, session) {
# defined in each session
s <- "session"
output$text <- renderText({
# defined each time this function is called
f <- "function"
})
} Why isn't In your case: ui <- fluidPage()
server <- function(input, output, session) {
wasCalled <- 0
observe({ # or a render func or a reactive
# the logic / conditionals you need...
mypkg::myfunc()
wasCalled <<- wasCalled + 1
})
} |
That works fine when you're developing the entire shiny app yourself. But
what if I want to do this from a separate package that is called from the
end user's shiny app? I won't have access to the server function.
…On Dec 15, 2016 8:22 AM, "Barbara Borges Ribeiro" ***@***.***> wrote:
I like the idea of having this explicitly as a session element. It seems
handy. However, I think I'm missing why exactly this isn't possible as of
now without tacking an attribute onto the session object.
The scoping rules for shiny:
# shared across all sessionsa <- "all"
ui <- fluidPage()
server <- function(input, output, session) {
# defined in each session
s <- "session"
output$text <- renderText({
# defined each time this function is called
f <- "function"
})
}
Why isn't s what you need?
In your case:
ui <- fluidPage()server <- function(input, output, session) {
wasCalled <- 0
observe({ # or a render func or a reactive
# the logic / conditionals you need...
mypkg::myfunc()
wasCalled <<- wasCalled + 1
})
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1512 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AA6IFFXldq3e2syFPIfqU9U1cp1c1qX5ks5rIT8TgaJpZM4LNtTF>
.
|
Yep, this is for advanced usage by module and package authors. |
Got it, thanks! |
Hi, The shinyStore package for storing local data using the HTML 5 storage is easy to use and works well. You could use it to store info per browser (not per session). David |
x-post from shiny-discuss
Suppose I have a package with an exported function that can be called from other people's shiny apps' server code. I want to know whether it's the first time they call this function or not. What's the best way to do this?
I can add an attribute to the
session
object but that sounds like a bad idea. I feel like there should be a simple solution I'm not seeingExample pseudocode:
And any shiny app can call it in server code, potentially multiple times
If I was working on a regular R package without a shiny app, I would use a global environment to store this global value. But in this case I want this to be per-session.
This isn't an issue, it's a question that's gotten no response on shiny-discuss. I might be abusing the Issues system, but I thought this would be a bit more considerate than my usual method of personally emailing @jcheng5
The text was updated successfully, but these errors were encountered: