【问题标题】:Error in eval: object 'input' not found in R Shiny appeval 中的错误:在 R Shiny 应用程序中找不到对象“输入”
【发布时间】:2016-06-16 23:43:26
【问题描述】:

我的 ui.R 看起来像这样

library(shiny)
library(Sim.DiffProc)

shinyUI(fluidPage(
      titlePanel("Sliders"),

      sliderInput(inputId = "theta",label="Theta:",
                  min=1, max=50, value=5),

      plotOutput("SDE")
    ))

而server.R如下

library(shiny)
library(Sim.DiffProc)


shinyServer(function(input, output)
{
  result<-reactive({
    f<-expression(x*(1-(x/1000))^input$theta*0.5)
    g<-expression(x*(1-(x/1000))^input$theta*0.2)
    snssde1d(drift=f,diffusion=g, M=5, x0=100)
  })

  output$SDE<-renderPlot({
    plot(result(), plot.type="single", col="lightgrey")})

})

我总是收到以下错误:找不到对象“输入” 我不知道有什么问题。为什么我的 theta 没有反应? 谢谢你的帮助!

【问题讨论】:

  • 漂移系数:两个变量 t 和 x 的表达式。 (这是f),扩散系数:两个变量t和x的表达式(这是g)
  • 程序在 R 中正常工作。我只是无法在 Shiny 中以正确的方式实现
  • 你的问题不是 Rshiny。这是expression函数的用法。表达式函数未计算 input$theta。您需要了解表达式函数接受什么输入。例如,如果您替换 input$theta,则为 5。它确实会产生输出。

标签: r shiny


【解决方案1】:

所以,正如我所提到的,您的问题不是 Rshiny。这是expression 的用法。

你在这里做的是

expression(x*(1-(x/1000))^input$theta*0.2)

基本上输出相同的表达式,而不用 input$theta 代替值 5。

你需要做的在下面

 f <- as.expression(bquote(x*(1-(x/1000))^.(input$theta)*0.2))

#bquote evaluates the expression enclosed in .()

这个输出

expression(x * (1 - (x/1000))^5 * 0.2)

希望能解决你的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    • 1970-01-01
    • 2020-09-28
    相关资源
    最近更新 更多