【发布时间】:2016-04-21 15:07:43
【问题描述】:
我正在编写一个闪亮的应用程序,其输出应取决于在闪亮的反应式表达式中计算的变量的值。我相信我没有复制实际的应用程序,而是用以下简单的应用程序重现了我的问题:
ui.R file:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Illustrating problem"),
sidebarPanel(
numericInput('id1', 'Numeric input, labeled id1', 0, min = 0, max = 100, step =5)
),
mainPanel(
h4('You entered'),
verbatimTextOutput("oid1"),
verbatimTextOutput("odic")
)
))
server.R file
library(shiny)
shinyServer(
function(input, output) {
output$oid1 <- renderPrint({input$id1})
x<-reactive({5*input$id1})
if (x()>50) output$oid2<-renderPrint({"You entered a number greater than 10"})
else output$oid2<-renderPrint({"You entered a number less than or equal to
10"})
}
)
如果我像这样运行它,那么我会收到错误:
错误 .getReactiveEnvironment()$currentContext() :`
在没有活跃的反应上下文的情况下不允许操作。 (你试过 做一些只能从反应式内部完成的事情 表达式或观察者。)
如果我将 if 语句更改为:if (x>50) ... 那么我得到错误:
x > 50 中的错误:比较 (6) 仅适用于原子和列表类型
当我将 if 语句更改为:if (reactive({(x>50)})) ... 然后我收到错误消息:
if (reactive({ : 参数不可解释为逻辑) 中的错误
非常感谢任何帮助
【问题讨论】: