Execute upon entrance/exit

38 views
Skip to first unread message

ShinyPinapple

unread,
Nov 23, 2015, 4:50:17 PM11/23/15
to Shiny - Web Framework for R
Hello,

I want to always reset a parameter when the user leaves the current tab(A) or enters in another tab(B), is there a way to do that?

Thank you!

Joe Cheng

unread,
Nov 23, 2015, 4:52:28 PM11/23/15
to ShinyPinapple, Shiny - Web Framework for R
See the tabsetPanel docs about the id parameter. If that's not enough to go on, please tell us a little more about what you want to do with this parameter--there are several ways to accomplish this.
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/4f72b71e-adeb-4069-b99f-b61db99a3485%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ShinyPinapple

unread,
Nov 23, 2015, 5:03:47 PM11/23/15
to Shiny - Web Framework for R, chenc...@gmail.com
Thanks Joe for the quick reply!

I am not sure how to use id parameter in tabsetPanel to solve my problem. Below I added detailed of what I want to accomplish:

In tab A, I have some summary tables and one 6*12(width) nvd3 plot. In tab B, Using conditional main panel,depending on the length of input C,  it shows either one 6*12(width) nvd3 plot or two side by side 6*6(width) nvd3 plot. I found that, if I exit tab B with two side by side graphs, the nvd3 plot in tab A also shrinks to 6*6. Therefore, whenever I leaves tab B, I want to reset the length of C which triggers the number of  plots in tab B to be 1, so that the nvd3 plot in tab A is always shown correctly.

Let me know if that makes sense, or I can provide more details.

Thank you!!

Joe Cheng

unread,
Nov 23, 2015, 5:06:24 PM11/23/15
to ShinyPinapple, Shiny - Web Framework for R
OK so you could reset the length of C, but to me that feels like you're skirting around the real problem, which is that the nvd3 plot in tab A shrinks to 6x6 for no reason... right?

Can you send a reproducible example for that?

ShinyPinapple

unread,
Nov 24, 2015, 10:29:45 AM11/24/15
to Shiny - Web Framework for R, chenc...@gmail.com
Joe,

I believe the shrinking issue has to do with how the rcharts package applies style info to charts. Whenever an nvd3 chart is rendered it sets the height and with for all of the other nvd3 plots in other tabs in shiny. My apologies that It might take me sometime to create a reproducible example. So for now, I feel like the best solution is probably to learn how to reset the length of C when leaving tab B. Any suggestion how to do that?

Thanks a lot!
Charlotte

Joe Cheng

unread,
Nov 24, 2015, 2:09:32 PM11/24/15
to ShinyPinapple, Shiny - Web Framework for R
In shiny server function:

# One of the few times you'll see me create a non-reactive variable outside
# of a observer that's assigned from within the observer...
lastTab <- NULL
observe({
  on.exit(lastTab <<- input$tab)
  if (identical(lastTab, "B") && !identical(input$tab, "B")) {
    # You're leaving B, adjust C
  }
})

Reply all
Reply to author
Forward
0 new messages