0

I have two files app.R and LoanHealthv2.R

app.R has following code. I am taking noc as input name which I need to pass as input to LoanHealthv2.R file and compute the results so that I can use the results of LoanHealthv2.R file in this app.

Also how can I make it reactive so that everytime I select different noc it generates new results?

########################## 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 looks like this

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 Answer 1

1

I am not sure if I understand fully what you are trying to do, but you could use a combination of reactiveValues and source in your application.

########################## 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)

Then in your LoanHealthv2.R file, you could make the appropriate changes:

#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)

})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.