【问题标题】:Shiny Selection box闪亮的选择框
【发布时间】:2018-10-01 12:31:52
【问题描述】:

我一直在尝试为轻度、中度、重度和末期肾功能损害等不同选项创建一个闪亮的选择列表框。我想编写与选择选项之一的值一起使用的代码,其余的应该是 0。有人可以帮我吗? 另一件事是输入数据将用于一个名为 input$RI(肾损伤)的方程。 这是我尝试使用的代码:

在用户界面中:

fluidPage(  

selectInput("RI",
            "Renal Impairment:",
            choices = list("Normal" = 1,
                           "Mild" = 2,
                           "Moderate + Severe" = 3,
                           "End Stage" = 4),
            selected = 1),

hr(),
fluidRow(column(4, verbatimTextOutput("0")))

)

在服务器文件中:

function(input, output) {

  output$RI <- renderPrint({ input$RI })


  if (RI == 1) {
    1 <- 0
    2 <- 0
    3 <- 0
    4 <- 0
  }


  if (RI == 2) {
    1 <- 0
    2 <- 1
    3 <- 0
    4 <- 0
  }


  if (RI == 3) {
    1 <- 0
    2 <- 0
    3 <- 1
    4 <- 0
  }


  if (RI == 4) {
    1 <- 0
    2 <- 0
    3 <- 0
    4 <- 1
  }

}

提前谢谢你。

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您需要适当地分配变量。您需要将反应输出包装在反应空间中。如果您需要返回多个项目,则需要将这些项目包装到一个列表中。

    library(shiny)
    
    ui <- fluidPage(  
    
      selectInput("RI",
                  "Renal Impairment:",
                  choices = list("Normal" = 1,
                                 "Mild" = 2,
                                 "Moderate + Severe" = 3,
                                 "End Stage" = 4),
                  selected = "Normal"),
    
      br(),
      fluidRow(column(4, verbatimTextOutput("myoutput")))
    
    )
    
    server <- function(input, output) {
    
      RI <- reactive({ 
    
        if (input$RI == 1) {
          a <- 0
          b <- 0
          c <- 0
          d <- 0
           out <- list(a,b,c,d)
        }
    
    
        if (input$RI == 2) {
          a <- 0
          b <- 1
          c <- 0
          d <- 0
          out <- list(a,b,c,d)
        }
    
    
        if (input$RI == 3) {
          a <- 0
          b <- 0
          c <- 1
          d <- 0
          out <- list(a,b,c,d)
        }
    
    
        if (input$RI == 4) {
          a <- 0
          b <- 0
          c <- 0
          d <- 1
          out <- list(a,b,c,d)
        } 
        return(out)
        })
    
      output$myoutput <- renderPrint({
        RI()
      })
    
    }
    
    shiny::shinyApp(ui = ui, server = server)
    

    【讨论】:

    • 非常感谢您的帮助,我仍然对如何在“ Cl
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-20
    • 2019-11-11
    • 2020-06-09
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多