作者swedrf0112 (M)
看板R_Language
标题Re: [问题] Shiny 使用javascript抓萤幕解析度
时间Wed Oct 21 14:13:30 2015
找到解决办法了,原因应该是要告诉 JavaScript Shiny已经准备好了,
所以要将UI.R的 script 修改为以下即可。
tags$script('
$(document).on("shiny:connected",function(e){
var Width = window.screen.width;
Shiny.onInputChange("MonitorWidth",Width);})
')
※ 引述《swedrf0112 (M)》之铭言:
: [问题类型]:程式谘询
: [软体熟悉度]:入门
: [问题叙述]:
: 想要找出使用者目前的解析度,
: 因此使用 JavaScript 的 window.screen.width ,
: 想将他传进 Shiny 中变成一个MonitorWidth 变数,
: 看了以下的参考连结,使用 Shiny.onInputChange 函数,
: 会一直在 renderPrint 传出 NULL的结果。
: http://tinyurl.com/ptsgpsq
: [程式范例]:
: shinyUI( bootstrapPage(
: tags$script('
: var Width = window.screen.width;
: Shiny.onInputChange("MonitorWidth", Width);
: ')
: ,verbatimTextOutput("results")
: ))
: shinyServer(function(input, output, session) {
: output$results = renderPrint({
: input$MonitorWidth
: })
: })
: [环境叙述]:
: [关键字]:Shiny JavaScript
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 223.136.96.50
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1445408012.A.7E1.html
1F:→ Wush978: 感谢分享 10/21 21:36
2F:推 cywhale: ya... just wanna find its solution.. thanks sharing^^ 10/21 22:56