我真正想做的是传递一个数字输出条件来生成条件面板。不过,我似乎无法将输出呈现为数字。
我的解决方法是使用感兴趣的数字条件生成 react 并将其作为文本传递到条件面板。不过,我也正在为此苦苦挣扎。
下面是一个例子:
目标是每当用户输入乘以 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
})
}
)
最佳答案
乍一看似乎Shiny needs to have the value displayed在某种条件下使用它,但这实际上并非如此:
outputOptions(output, 'big', suspendWhenHidden=FALSE)
您将告诉 Shiny 在该值不可见时也考虑该值。
即使您在服务器函数中添加了这一行,您还需要进行另一项更改:需要计算 big 的值,因此:
output$big<-renderText({
over_100
})
必须变成这样:
output$big<-renderText(over_100())
希望这可以帮助你。
关于r - 作为条件面板条件的数字输出值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29833222/