[英]Shiny Send plain string from server to ui
i'm facing an issue that probably is easy too solve but is bugging me. 我正面临一个可能很容易解决的问题,但却在困扰着我。
I have a global.R script where I use JS to compute the screen height 我有一个global.R脚本,我使用JS来计算屏幕高度
jscode_for_screen_Height <- '$(document).on("shiny:connected", function(e) {
var jsHeight = screen.height;
Shiny.onInputChange("GetScreenHeight",jsHeight); });'
This variable is used in several parts in my server.R and it works properly. 这个变量在我的server.R中的几个部分中使用 ,它可以正常工作。 Eg
例如
output$viewDataCTgov <- DT::renderDataTable({
DT::datatable(data_to_render_CTgov(),
options = list(scrollX = TRUE,scrollY = paste(input$GetScreenHeight,"px",sep=""),
scrollCollapse=TRUE,pageLength = 100,searchHighlight = TRUE), escape = FALSE)
})
Now I'm creating a leaflet map and in ui.R I have 现在我正在创建一个传单地图,在ui.R我有
leafletOutput("mymap", height = XXX )
leafletoutput accepts a string as height parameter (eg "400") leafletoutput接受一个字符串作为高度参数(例如“400”)
Here the problems: 这里的问题:
1) I can't use input$GetScreenHeight because i'm on the ui.R and input is not in the scope of the script. 1)我不能使用input $ GetScreenHeight,因为我在ui.R上并且输入不在脚本范围内。
2) I can't figure out how to pass a plain string to ui.R from the server.R 2)我不能找出如何纯字符串从server.R传递到ui.R
What I tried so far is to use in server.R 我到目前为止尝试的是在server.R中使用
output$ScreenHeightvalue <- paste0(input$GetScreenHeight)
And in ui.R 在ui.R
leafletOutput("mymap", height =(textOutput("ScreenHeightvalue")))
but doesn't work due to the fact that textOutput("ScreenHeightvalue") is not a plain string. 但是由于textOutput(“ScreenHeightvalue”)不是普通字符串这一事实不起作用。
How can I pass paste0(input$GetScreenHeight) from the server.R to the ui.R as plain string? 如何将paste0(输入$ GetScreenHeight)从server.R传递给ui.R作为普通字符串?
I don't know how to pass a plain string from server to ui, but you can define your lealfetOutput in the server by using a renderUI 我不知道如何将普通字符串从服务器传递到ui,但是您可以使用renderUI在服务器中定义lealfetOutput
library(shiny)
library(leaflet)
ui <- fluidPage(
uiOutput("test")
)
server <- function(input, output) {
output$myMap <- renderLeaflet({
leaflet() %>%
addTiles() %>%
setView(-93.65, 42.0285, zoom = 17)
})
output$test <- renderUI({
tagList(
leafletOutput("myMap", height = paste0(input$GetScreenHeight))
)
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.