闪亮:为什么在服务器端使用temporay变量作为输出失败?

闪亮:为什么在服务器端使用temporay变量作为输出失败?,r,function,expression,shiny,R,Function,Expression,Shiny,下面是一个简单的闪亮应用程序: ui.R library(shiny) shinyUI(bootstrapPage( numericInput("mymun", "enter a number",0), textOutput("mytext") )) server.R library(shiny) test <- function(input, output){ renderText(paste("this is my number:",input$mymun)) }

下面是一个简单的闪亮应用程序:

ui.R

library(shiny)
shinyUI(bootstrapPage(
  numericInput("mymun", "enter a number",0),
  textOutput("mytext") 
))
server.R

library(shiny)
test <-  function(input, output){
  renderText(paste("this is my number:",input$mymun))
}

shinyServer(function(input, output) { 
  output$mytext <- test(input, output)
})
library(shiny)
test <-  function(input, output){
  renderText(paste("this is my number:",input$mymun))
}

shinyServer(function(input, output) { 
  tmp <- test(input, output)
  output$mytext <- tmp
})
错误消息是:

Error in substitute(value)[[2]] : 
 object of type 'symbol' is not subsettable
有人能提供第二个失败和第一个失败的线索吗?
我猜这是由于表达式处理和Shining server的反应逻辑造成的,但我不清楚这一点

真正弄清楚这一点的最佳方法是重新阅读+,以确保您完全理解反应性和范围(在SO中发布具有开创性的教程文本毫无意义)

要获得接近您正尝试执行的操作,您需要在
server.R
中执行以下操作:

library(shiny)

shinyServer(function(input, output) { 

  test <- reactive({
    return(paste("this is my number:",input$mymun))
  })

  output$mytext <- renderText({
    tmp <- test()
    return(tmp)
  })

})
库(闪亮)
shinyServer(函数(输入、输出){

测试很明显,使用反应式函数是正确的方法,但是你能解释一下是什么把OPs示例搞砸了吗,因为他的问题不是“如何让它工作”,而是“为什么示例1工作而示例2不工作”。这就是“让我们不要重复教程中的内容”因为他们在那里解释得很好。谢谢你的回答!我现在很清楚为什么第二个代码失败了。但是,要理解第一个代码为什么没有失败并不是那么简单。我猜
output$mytext
是以某种方式强制给观察者的,但这仍然不清楚。@hrbrmstr请重新发布到tutoria的链接好吗ls?他们现在不在。谢谢。