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