2023-05-21

How can the same set of dependent filters be used with two datasets to generate at least two outputs?

I am a volunteer for a start-up, non-profit that solicits contributions of mineral interests from private royalty owners. Contributed interests are then aggregated and sold with the proceeds awarded as grants to promote the development of technologies to fight climate change.

To expand our fund-raising efforts, we want to set up a shiny web app for owners who could be prospective donors. These owners could search our database, locate their interests and learn the amount of tax deduction they could gain through a donation to our non-profit (First Objective, based on "Sample_Tax_Data", see: (https://docs.google.com/spreadsheets/d/1wKe9VR_Cs2V_CJGNipbuCaUFR21eTHE0/edit?usp=share_link&ouid=118028955904508148375&rtpof=true&sd=trueto)).

Owners could also access alternative valuations, based upon historical oil and gas production associated with their Lease, that could increase the amount of their tax deduction for those Leases with additional development potential (Second Objective based upon "Sample_Prod_Data", see (https://docs.google.com/spreadsheets/d/1Pq6bfiaATGZaGHtxOrqekJjTp4g3k_Rj/edit?usp=share_link&ouid=118028955904508148375&rtpof=true&sd=true)).

In the case of the First Objective: Using code I found on this site (see below), I was able to create a series of dependent filters that enable owners to sort through the 10 million lease interests in our database to locate their particular lease(s).

library(readxl) library(shiny) library(tidyverse)

TaxData <- Sample_Tax_Data

shinyApp( ui = pageWithSidebar( headerPanel("Find My Royalty Interest"), sidebarPanel( selectizeInput(inputId = "County", label = "Select County", choices = NULL, options = list(placeholder = 'select') ),

  selectizeInput(inputId = "Operator",
                 label = "Select Operator",
                 choices = NULL,
                 options = list(placeholder = 'select',
                                onInitialize = I('function() { this.setValue(""); }')
                 )),
  
  selectizeInput(inputId = "Lease",
                 label = "Select Lease",
                 choices = NULL,
                 options = list(placeholder = 'select',
                                onInitialize = I('function() { this.setValue(""); }')
                 )),
  
  selectizeInput(inputId = "Owner",
                 label = "Select Owner",
                 choices = NULL,
                 options = list(placeholder = 'select',
                                onInitialize = I('function() { this.setValue(""); }')
                 )),
  
   ),

mainPanel(
  tableOutput("TaxTable")
)

),

server = function(input, output, session) {

TaxFil <- reactive({
  
  TaxData %>%
    filter(County == input$County) %>%
    filter(Operator == input$Operator) %>%
    filter(Lease == input$Lease) %>%
    filter(Owner == input$Owner) 
  

})

updateSelectizeInput(
  session = session,
  inputId = "County",
  choices = sort(unique(as.character(TaxData$County))),
  selected = "",
  options = list(placeholder = 'select'),
  server = TRUE
)

observeEvent(input$County,{
  choice_Operator <- sort(unique(as.character(TaxData$Operator[which(TaxData$County==input$County)])))
  
  updateSelectizeInput(
    session = session,
    inputId = "Operator",
    choices = choice_Operator
  )
})

observeEvent(input$Operator,{
  choice_Lease <- sort(unique(as.character(TaxData$Lease[which(TaxData$County==input$County &
                                                                 TaxData$Operator==input$Operator)])))
  
  updateSelectizeInput(
    session = session,
    inputId = "Lease",
    choices = choice_Lease
  )
})

observeEvent(input$Lease,{
  choice_Owner <- sort(unique(as.character(TaxData$Owner[which(TaxData$County==input$County &
                                                                 TaxData$Operator==input$Operator &
                                                                 TaxData$Lease==input$Lease)])))
  
  updateSelectizeInput(
    session = session,
    inputId = "Owner",
    choices = choice_Owner
  )
})

output$TaxTable <- renderTable({TaxFil()})

},

options = list(height = 500)

)

In the case of the Second Objective: I have not been able to write the code to support the use of that same series of dependent filters, and the results therefrom, to enable owners to access the alternative valuations associated with their interests.

The first option I considered was a re-use of the filters supporting the First Objective (see code above). In such case, the filters would be used to identify both the Owner (and the assigned "Tax Value"-first objective) as well as the Lease (and the production of "Oil" and "Gas" therefrom for purposes of projecting additional value-second objective). This seemed like it would be the most logical way to filter for the Two Objectives, but I couldn't get it to work.

The next thing I tried was to recreate the filter and use it separately for the Second Objective (with the original filter just being used for purposes of selecting the Owner.) I could't get this to work either and it also did not seem like a very economical coding option anyway.

The final thing I tried was a merger of the two data bases. But with many leases having over 30 years of monthly production history and thousands of owners in some cases, the combined file would be at least 20 times bigger and difficult to work with.

So in summary, I am looking for help coding one set of filters that can be applied to at least two different databases for at least two different outputs. I have reviewed previous questions/answers and found several that are close in nature, such as those answered by NicE, but with my limited experience I couldn't extrapolate to my particular objective. I am obviously new to this and would really appreciate your support.



No comments:

Post a Comment