楼主: oliyiyi
1183 0

Stop Shiny and Close Browser Together [推广有奖]

版主

已卖:2994份资源

泰斗

1%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
7
论坛币
66105 个
通用积分
31671.0967
学术水平
1454 点
热心指数
1573 点
信用等级
1364 点
经验
384134 点
帖子
9629
精华
66
在线时间
5508 小时
注册时间
2007-5-21
最后登录
2025-7-8

初级学术勋章 初级热心勋章 初级信用勋章 中级信用勋章 中级学术勋章 中级热心勋章 高级热心勋章 高级学术勋章 高级信用勋章 特级热心勋章 特级学术勋章 特级信用勋章

楼主
oliyiyi 发表于 2016-5-28 19:37:36 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币


(This article was first published on data_steve, and kindly contributed to R-bloggers)

I’ve been playing with shiny at work for a project Tyler and I have been pushing forward.

My Goal

We wanted to be able to deploy local instances of shiny app and then when user is done with session, the user can close out the session by closing the browser and shutting down shiny server at same time.

StackOverflow and Google groups had several stepping stones to help in the process, which with a bit of refactoring did the trick. The first link pointed to the javascript snippet I could possibly use, though no real suggestions on how to use it.

session$onSessionEnded(function() {     stopApp() })

Next, shiny’s google group had a tip on inserting Javascript into shiny, which didn’t work for me but evidently did for others. Then, back at StackOverflow, I found that the javascript above has its drawbacks if a user refreshed their session midway.

My Solution and Edit

The solution that works for me in this minimal shinyApp demo was to edit the SO answer at the last link. (At time of this post, my edit had not been approved yet, so you may find the SO link has code that doesn’t work.) Basically, just add a close button that shuts down shiny server locally and closes browser, simple enough. And in shinyUI, one could possibly make this button appear only once end of app session was complete.

I had to edit the original answer because I couldn’t get the proposed solution to observe the stopApp()command before window.close() closed the connection to shiny. So, I added a simple setTimeoutsolution around the window.close(); action to give shiny enough time to observe, combining this SO absolute minimal clue of an answer with good ol’ W3’s practice session example.

library(shiny) runApp(list(   ui = bootstrapPage(     tags$button(       id = 'close',       type = "button",       class = "btn action-button",      ,  # close browser       "Close window"     )   ),   server = function(input, output) {     observe({       if (input$close > 0) stopApp()                             # stop shiny     })   } ))

I thought I’d write all this up in one place so that all my running around wasn’t a waste.

Tweet


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:together browser Browse Shiny Close Browser

缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-3 06:37