r - 作为条件面板条件的数字输出值

标签 r shiny

我真正想做的是传递一个数字输出条件来生成条件面板。不过,我似乎无法将输出呈现为数字。

我的解决方法是使用感兴趣的数字条件生成 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/

相关文章:

r - 在 Shiny 中对静态图像进行动画处理

css - 滚动条未显示在 Shiny 中

jquery - R Shiny 的鼠标悬停到所有表格单元格

r - Shiny 的 Azure WebApp 作为 Azure SQL Server 的用户进行身份验证

r - 在 ggplot2 中 - 如何确保 geom_errorbar 在使用 xlim() 控制 x 轴时显示所有点的条形限制

r - 在 R 中,将函数应用于数据框的行并返回数据框

r - 具有最新可用观测值的散点图

r - 将 igraph 中的边列表写入 R 中的文件;如何写顶点名称而不是顶点ID

r - 查找一个字符串是否包含在 R 中的另一个字符串中

r - Shiny 的 SelectInput 为 renderImage 生成文件路径