作者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://www.ptt.cc/bbs/R_Language/M.1445408012.A.7E1.html
→ Wush978: 感謝分享 10/21 21:36
推 cywhale: ya... just wanna find its solution.. thanks sharing^^ 10/21 22:56