Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何将变量从服务器传递到ui并显示在模板中?_R_Shiny - Fatal编程技术网

R 如何将变量从服务器传递到ui并显示在模板中?

R 如何将变量从服务器传递到ui并显示在模板中?,r,shiny,R,Shiny,我试图从数据帧中读取一个值,该数据帧最终将每2分钟更新一次。目前,我正在努力通过htmltemplate将数据发送到shiny中的UI 我尝试过各种呈现和输出UI的实现,但似乎无法理解 library(shiny) test_date <- as.Date(c('2019-01-01','2019-01-02','2019-01-03','2019-01-04')) score <- c(75,80,85,90) my_dataframe <- data.frame(test

我试图从数据帧中读取一个值,该数据帧最终将每2分钟更新一次。目前,我正在努力通过htmltemplate将数据发送到shiny中的UI

我尝试过各种呈现和输出UI的实现,但似乎无法理解

library(shiny)

test_date <- as.Date(c('2019-01-01','2019-01-02','2019-01-03','2019-01-04'))
score <- c(75,80,85,90)
my_dataframe <- data.frame(test_date, score)

ui <- htmlTemplate(
  text_ = '
  <html>
  <head> 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <script type="application/shiny-singletons"></script>
  <script type="application/html- dependencies">json2[2014.02.04];jquery[1.12.4];shiny[1.2.0]</script>
  </head>
  <body>
  <p style="color:red">{{outputUI("score_value")}}</p>
  </body>
  </html>'
)
server <- function(input, output, session) {
  output$score_value <- renderUI(
    {mean(my_dataframe$score)}
  )
}
shinyApp(ui, server)
库(闪亮)

test_date现在无法测试,但是您是否尝试过像这样在shinyui函数中包装htmltemplate

ui <- shinyUI(htmlTemplate(
  text_ = '
  <html>
  <head> 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <script type="application/shiny-singletons"></script>
  <script type="application/html- dependencies">json2[2014.02.04];jquery[1.12.4];shiny[1.2.0]</script>
  </head>
  <body>
  <p style="color:red">{{renderUI("score_value")}}</p>
  </body>
  </html>'
))

ui现在无法测试,但是您是否尝试过像这样在shinyui函数中包装htmltemplate

ui <- shinyUI(htmlTemplate(
  text_ = '
  <html>
  <head> 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <script type="application/shiny-singletons"></script>
  <script type="application/html- dependencies">json2[2014.02.04];jquery[1.12.4];shiny[1.2.0]</script>
  </head>
  <body>
  <p style="color:red">{{renderUI("score_value")}}</p>
  </body>
  </html>'
))

ui首先,代码没有在我的机器上运行,只是灰色页面。。。奇怪

第二个outputUI不是有效的函数,您使用的是哪个版本? 我使用:

uiOutput()

第三,您的输出看起来是正确的,我认为,您已经告诉renderUI它应该包含什么(渲染元素)

renderUI({
标签列表(
renderText(
平均值(my_dataframe$分数)
)
)
})

编辑: 缺少某些依赖项。下面是添加了一些依赖项的完整工作代码:

library(shiny)

test_date <- as.Date(c('2019-01-01','2019-01-02','2019-01-03','2019-01-04'))
score <- c(75,80,85,90)
my_dataframe <- data.frame(test_date, score)

ui <- htmlTemplate(
  text_ = '

    <html>
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
    <script type="application/shiny-singletons"></script>  
    <script type="application/html-dependencies">
    json2[2014.02.04];
  jquery[1.11.3];
  shiny[0.13];
  ionrangeslider[2.0.12];
  strftime[0.9.2]
  </script>
    <script src="shared/json2-min.js"></script>
    <script src="shared/jquery.min.js"></script>
    <link href="shared/shiny.css" rel="stylesheet"/>
    <script src="shared/shiny.min.js"></script>
    <link href="shared/ionrangeslider/css/ion.rangeSlider.css" 
  rel="stylesheet"/>
    <link href="shared/ionrangeslider/css/ion.rangeSlider.skinShiny.css" 
  rel="stylesheet"/>
    <script src="shared/ionrangeslider/js/ion.rangeSlider.min.js"></script>
    <script src="shared/strftime/strftime-min.js"></script>
    </head>
    <body>
    <p style="color:red">{{ uiOutput("score_value") }}</p>
    </body>
    </html>
'
)
server <- function(input, output, session) {
  output$score_value <- renderUI({
    tagList(
      renderText(
        mean(my_dataframe$score)
      )
    )
  })
}
shinyApp(ui = ui, server = server)
库(闪亮)

测试日期第一个代码,不在我的机器上运行,只是灰色页面。。。奇怪

第二个outputUI不是有效的函数,您使用的是哪个版本? 我使用:

uiOutput()

第三,您的输出看起来是正确的,我认为,您已经告诉renderUI它应该包含什么(渲染元素)

renderUI({
标签列表(
renderText(
平均值(my_dataframe$分数)
)
)
})

编辑: 缺少某些依赖项。下面是添加了一些依赖项的完整工作代码:

library(shiny)

test_date <- as.Date(c('2019-01-01','2019-01-02','2019-01-03','2019-01-04'))
score <- c(75,80,85,90)
my_dataframe <- data.frame(test_date, score)

ui <- htmlTemplate(
  text_ = '

    <html>
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
    <script type="application/shiny-singletons"></script>  
    <script type="application/html-dependencies">
    json2[2014.02.04];
  jquery[1.11.3];
  shiny[0.13];
  ionrangeslider[2.0.12];
  strftime[0.9.2]
  </script>
    <script src="shared/json2-min.js"></script>
    <script src="shared/jquery.min.js"></script>
    <link href="shared/shiny.css" rel="stylesheet"/>
    <script src="shared/shiny.min.js"></script>
    <link href="shared/ionrangeslider/css/ion.rangeSlider.css" 
  rel="stylesheet"/>
    <link href="shared/ionrangeslider/css/ion.rangeSlider.skinShiny.css" 
  rel="stylesheet"/>
    <script src="shared/ionrangeslider/js/ion.rangeSlider.min.js"></script>
    <script src="shared/strftime/strftime-min.js"></script>
    </head>
    <body>
    <p style="color:red">{{ uiOutput("score_value") }}</p>
    </body>
    </html>
'
)
server <- function(input, output, session) {
  output$score_value <- renderUI({
    tagList(
      renderText(
        mean(my_dataframe$score)
      )
    )
  })
}
shinyApp(ui = ui, server = server)
库(闪亮)

test_date您的代码遗漏的第一个主要内容是
{{{headContent()}}

库(闪亮)

test_date您的代码遗漏的第一个主要内容是
{{{headContent()}}

库(闪亮)

测试日期我有,它不会产生一个单独的结果。谢谢你的想法和贡献。我有,但它不会产生一个单独的结果。谢谢你的想法和贡献。这一个应该做什么?
outputUI(“分数值”)
?这一个应该做什么?
outputUI(“分数值”)
?我选择这个作为答案,因为不是渲染的变化导致了我的不幸,而是我缺少的头部内容。感谢您的指导和支持文档。我之所以选择这一点作为答案,是因为并不是渲染的变化导致了我的不幸,而是我缺少的标题内容。感谢您的指导和支持文档。