【发布时间】:2015-04-24 05:57:59
【问题描述】:
我真正想做的是传递一个数字输出条件来生成条件面板。不过,我似乎无法将输出呈现为数字。
我的解决方法是使用感兴趣的数字条件生成反应,并将其作为文本传递给条件面板。但是,我也在为此苦苦挣扎。
下面是一个例子:
目标是在用户输入乘以 5 大于 100 的数字时打开条件面板 是 - 我知道我可以通过设置 input$number >20 来做到这一点 这是我正在研究的一个简化示例。 问题是使用数字输出作为条件面板
谢谢!
山姆
library(shiny)
shinyApp(
ui = fluidPage(
fluidRow(
wellPanel(
numericInput("number", label = "Choose a Number between -100 and 100",
min = -100, max = 100, value = 0))),
fluidRow(wellPanel(textOutput("text_out"))),
fluidRow(conditionalPanel(
condition = "output.big == '1' ",
fluidRow(h1("You've selected a number larger than 20!"))))),
server = function(input, output, session){
# I want to execute a function on a numeric input
times_5<-reactive({
input$number*5
})
# I can't get the condition to work with a numeric query
# So, I run the query on the server side and generate an if/else statement
# to pass a text variable
over_100<-reactive({
if(times_5()>100){
return(1)
} else{
return(0)
}
})
output$text_out<-renderText({
paste("This is text out put of the number ", input$number, "multiplied by 5 to equal ", times_5(), over_100())
})
# I can't find a render function that generates numeric output
# Even still this outputtext doesn't seem to work in the conditional statement.
output$big<-renderText({
over_100
})
}
)
【问题讨论】: