admin管理员组文章数量:1356011
I want to get screen resolution from JavaScript, stored in the GetScreenWidth
variable on Shiny Server.
I tried the reference:
- Receiving data from .js in server.R shiny
- /
So I have:
ui.R
shinyUI(
bootstrapPage(
verbatimTextOutput("results")
,tags$script('
var jsWidth = screen.width;
Shiny.onInputChange("GetScreenWidth",jsWidth);
')
)
)
server.R
shinyServer(function(input,output){
output$results=renderPrint({
input$GetScreenWidth
})
})
It will return NULL
by verbatimTextOutput
.
How should I modify the code? Thanks!
I want to get screen resolution from JavaScript, stored in the GetScreenWidth
variable on Shiny Server.
I tried the reference:
- Receiving data from .js in server.R shiny
- https://ryouready.wordpress./2013/11/20/sending-data-from-client-to-server-and-back-using-shiny/
So I have:
ui.R
shinyUI(
bootstrapPage(
verbatimTextOutput("results")
,tags$script('
var jsWidth = screen.width;
Shiny.onInputChange("GetScreenWidth",jsWidth);
')
)
)
server.R
shinyServer(function(input,output){
output$results=renderPrint({
input$GetScreenWidth
})
})
It will return NULL
by verbatimTextOutput
.
How should I modify the code? Thanks!
Share Improve this question edited Jul 21, 2017 at 13:29 Badacadabra 8,5277 gold badges31 silver badges54 bronze badges asked Oct 21, 2015 at 2:42 Robin ChenRobin Chen 1033 bronze badges1 Answer
Reset to default 11The problem is that you're running the JavaScript code before Shiny is initialized. You can use the new feature that tells you when shiny is ready, here's example code
jscode <-
'$(document).on("shiny:connected", function(e) {
var jsWidth = screen.width;
Shiny.onInputChange("GetScreenWidth",jsWidth);
});
'
library(shiny)
runApp(shinyApp(
ui = fluidPage(
tags$script(jscode)
),
server = function(input, output, session) {
observe({
cat(input$GetScreenWidth)
})
}
))
本文标签: How to get screen resolution from JavaScript in R ShinyStack Overflow
版权声明:本文标题:How to get screen resolution from JavaScript in R Shiny? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744043526a2581105.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论