我有两个文件app.R
和LoanHealthv2.R
app.R具有以下代码。我将noc
作为输入名称,我需要将其作为输入传递给LoanHealthv2.R
文件并计算结果,以便可以在此应用程序中使用LoanHealthv2.R
文件的结果。
又如何使它具有反应性,以便每次选择不同的noc
时都会产生新结果?
########################## Ui function ################################
ui=fluidPage(
titlePanel("Loan Health"),
fluidRow(
selectInput("noc","Name of Customer", customers[,1], selected = NULL, multiple = FALSE,
selectize = TRUE, width = NULL, size = NULL)
),
mainPanel(
plotOutput("Plot", width = "100%", height = "400px", click = NULL,
dblclick = NULL, hover = NULL, hoverDelay = NULL,
hoverDelayType = NULL, brush = NULL, clickId = NULL,
hoverId = NULL, inline = FALSE)
)
)
########################## server function ################################
server <- function(input, output) {
output$Plot<-renderPlot({
customer<-input$noc #Name of customer
plot(SalesClientData$Date,SalesClientData$DPD,type="l")
})
}
shinyApp(ui, server)
LoanHealthv2.R
看起来像这样
customer = "A1" #<-I want this to be equal to input `noc` from app.R and compute the result below and make it available so that I can plot output.
account<-customers[which(customers[,1]==customer), 2]
start<- customers[which(customers[,1]==customer), 3]
SalesClientData = subset(POSData,POSData$Loan_Account_Number==account)
答案 0 :(得分:1)
我不确定我是否完全了解您要做什么,但是您可以在应用程序中结合使用reactiveValues
和source
。
########################## Ui function ################################
ui=fluidPage(
titlePanel("Loan Health"),
fluidRow(
selectInput("noc","Name of Customer", customers[,1], selected = NULL, multiple = FALSE,
selectize = TRUE, width = NULL, size = NULL)
),
mainPanel(
plotOutput("Plot", width = "100%", height = "400px", click = NULL,
dblclick = NULL, hover = NULL, hoverDelay = NULL,
hoverDelayType = NULL, brush = NULL, clickId = NULL,
hoverId = NULL, inline = FALSE)
)
)
########################## server function ################################
server <- function(input, output) {
rv <- reactiveValues()
output$Plot<-renderPlot({
customer<-input$noc #Name of customer
rv$customer <- customer
plot(SalesClientData$Date,SalesClientData$DPD,type="l")
})
source("LoanHealthv2.R", local = TRUE)
}
shinyApp(ui, server)
然后在您的LoanHealthv2.R
文件中,进行适当的更改:
#Assuming you want to output this as a table using the `DT` package
output$CustomerDF <- renderDT ({
req(rv$customer)
customer = rv$customer
account<-customers[which(customers[,1]==customer), 2]
start<- customers[which(customers[,1]==customer), 3]
SalesClientData = subset(POSData,POSData$Loan_Account_Number==account)
datatable(SalesClientData)
})