Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R中的另一个对象中使用输出对象?_R_Shiny - Fatal编程技术网

如何在R中的另一个对象中使用输出对象?

如何在R中的另一个对象中使用输出对象?,r,shiny,R,Shiny,我正在从csv文件中提取数据,当我想在另一个名为credit\u decision的输出对象中使用credit\u salary对象时,出现一个错误:“credit\u salary”not found。我如何使用credit\u salary输出来比较工资和数字(例如600)在信贷决策中 library(shiny) library(shinythemes) ui <- fluidPage(theme=shinytheme("superhero"), ti

我正在从csv文件中提取数据,当我想在另一个名为credit\u decision的输出对象中使用credit\u salary对象时,出现一个错误:“credit\u salary”not found。我如何使用credit\u salary输出来比较工资和数字(例如600)在信贷决策中

library(shiny)
library(shinythemes)
ui <- fluidPage(theme=shinytheme("superhero"),
                titlePanel(h1("NON Bank", align="center")),
                tags$br(),
  sidebarLayout(
    sidebarPanel(
      fileInput("file1", "Upload the csv file containing customers' data",
                accept = c(
                  "text/csv",
                  "text/comma-separated-values,text/plain",
                  ".csv")
      ),
      "Enter the ID of customer",
      textInput("id","","",placeholder = "Enter ID")),

    mainPanel(h3("Data of the customer"),
      tableOutput("contents"),
      textOutput("cutoff"),
      tags$br(),
      "Salary of the customer: ",
      tags$br(),
      uiOutput("sal"),
      tags$br(),
      "Credit score according to customer's salary : ",
      uiOutput("credit_salary"),
      tags$br(),
      "Decision :",
      uiOutput("credit_decision")


    )
  )
)
库(闪亮)
图书馆(shinythemes)

ui请通过包括(1)最小样本数据和(2)代码来再现错误(例如,我们没有你闪亮的应用程序的
ui
部分),使你的帖子具有可再现性
renderText
(这是
credit\u salary
调用的)获取从函数返回的值,并使用
cat
将其转换为字符串。所以我不知道你所说的“我如何使用信用卡工资输出”是什么意思。
credit\u salary
输出是一个字符串(您可能会在应用程序的
ui
部分使用该字符串)。@MauritsEvers很抱歉不清楚。我是R编程新手。我刚刚通过链接添加了应用程序的ui部分和图片。如何更改代码以比较**credit\u salary**(从函数返回的值)有数字吗?这仍然是不可复制的,因为您没有提供任何样本数据。不清楚
credit\u salary
应该是什么。正如我所说,
renderText
返回一个字符串,而不是一个数值!既然
mydata
是一个反应式表达式,为什么不直接从
mydata中提取您需要的任何数量呢?因此,也许可以将
credict_salary>600
替换为
mydata()[input$id,3)*2>600
?这是一个猜测,因为我们没有任何示例数据可以使用。非常感谢我解决了这个问题
  server <- function(input, output) {

    output$myid <- renderText(input$id)
    output$cutoff = renderText({
    paste("Let cutoff = ", 600)
  })

 output$contents <- renderTable({
    req(mydata())

       switch(input$id,
           mydata()[input$id,]
           )
  })

    mydata <- reactive({
    req(input$file1, file.exists(input$file1$datapath))
    read.csv(input$file1$datapath)  
  })

    output$credit_salary <- renderText({
    x <- mydata()[input$id,3]
    y <- 2*x  
  })

    output$credit_decision <- renderText({
    if( credit_salary > 600){ # *****THE PROBLEM IS HERE******
      print("Credit is available")
    }
  })
}
```[enter image description here][1]


  [1]: https://i.stack.imgur.com/ReDNJ.png