Как передать вход из app.R в другой скрипт и вернуть объекты? - PullRequest
0 голосов
/ 24 марта 2019

У меня есть два файла 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)

1 Ответ

1 голос
/ 24 марта 2019

Я не уверен, полностью ли я понимаю, что вы пытаетесь сделать, но вы можете использовать комбинацию 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)

})
...