精華區beta R_Language 關於我們 聯絡資訊
找到解決辦法了,原因應該是要告訴 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