0

I am trying to make a webap that provides inventory information based on user queries. All of the data is located in a flat file and I am currently running R version 3.2.5 (2016-04-14) on windows 7(64bit).

I am stuck trying to figure out how to provide the corresponding pdf based on an input query after the user submits the query, followed by clicking a new action button to open the pdf. All of the pdf's( thousands of them) are stored in my www directory btw...

I have looked at a lot of posts, but they all pertain to opening a single pdf file with iframe or window.open() in the UI script. That works fine, but I can not figure out how to generate the object on the server side form multiple files.

My code:

shinyUI(fluidPage(


        tags$head(
          tags$style(type="text/css", ".dataTables_filter {display: none;    }", "tfoot {display:none;}",HTML("
  @import url('//fonts.googleapis.com/css?family=Arima+Madurai|Cabin:400,700');

  h1 {
    font-family: 'Arima+Madurai', bold;
    font-weight: 500;
    line-height: 1.1;

  }

"))
        ),




headerPanel("Chem-Share Search Page"),
# Application title
title="Chem-Share Search Page",


# Sidebar with controls to select a dataset 
sidebarLayout(
  sidebarPanel( 
    conditionalPanel("Search by Chemicals",

                     selectizeInput("obs", "Query Chemical Name",choices=NULL, options = list(maxOptions = 5137)),
                     textInput("txt","Query Barcode, CAS#, or CAT#"),
                     actionButton("submit", "Submit")),

    actionButton('pdfview', 'View SDS', onclick = "window.open('2-Propanol.pdf')") #### this works when I know the pdf, but how to make it work from subseting a list of pdf's storred locally

  ),




  # Show a summary of the dataset and a data table 
  mainPanel(


    tabsetPanel(


      tabPanel('By Name', dataTableOutput('mytable1')),
      tabPanel('By Catalog #', dataTableOutput('mytable2')),
      tabPanel('By Barcode', dataTableOutput('mytable3')),
      tabPanel('By CAS #',dataTableOutput('mytable4')),


      tags$head(
        tags$style(type = "text/css", "a{color: #000000;}")
      )
    )
  )
),


 includeHTML("www/mail_to.html"))

)

Server

require(dplyr);require(data.table);require(xlsx)
locals<- getwd()



shinyServer(function(input, output,session) {

  values <- reactiveValues(default = 0)




  omw_inventory_2016 <- as.data.table(read.csv("2016_inventory_database.csv",stringsAsFactors = F, encoding = 'UTF-8',na.strings = c("NA","N/A","","none","lookup","look.up","look up")))
  omw_inventory_2016<-omw_inventory_2016[Transaction.Type!="Disposal"][Transaction.Type!="Dispose"]
  searching <- unique(omw_inventory_2016$Product.Name)



  uom <- read.csv("Inventory_Instruction_.csv",stringsAsFactors = F)
  new_omw <- merge(omw_inventory_2016,uom,by="Unit.of.Measure",all.x = TRUE)
  omw_inventory_2016<- new_omw;rm(new_omw)
  sds <- as.data.table(read.csv("sds_list.csv",stringsAsFactors = F))
  sds<- sds %>% select(Product.Name,Product.Code,sds1)
   import <-read.xlsx("2310.xlsx",sheetName = "Sheet2",stringsAsFactors = F,header = T)
  updateSelectizeInput(session,"obs",choices=searching,server=TRUE) 
  observeEvent(input$submit,{values$default <- input$submit})
  setkey(omw_inventory_2016,"Product.Name")

  output$downloadData <- downloadHandler( 



    filename = function(){paste("chem_share_template",".csv",sep = "")},
    content = function(file){
      write.csv(import,file)
    }

  )

  # ### **I am trying to subset the pdf name to generate the filepath**
  # **Does not work**
  # output$pdfview <- renderText({
  #  pdfs<-sds[Product.Code %chin% input$txt,sds1]
  # #  pdfs<- paste("file:///",locals,"/www/",pdfs,sep = "")
  # # pdfs
  # 
  # })
#  **I have tried this too**
#   view_pdf<- function(important){
#     pdfs<-sds[Product.Code %chin% input$txt,sds1]
#     pdfs<- paste('"file:///',locals,'/www/',pdfs,'"',sep = "")
#     paste('src=',pdfs,',style="height:100%; width:100%; scrolling:yes"',sep="")
#   }
# 
#   output$pdfview <- renderText({view_pdf(input$txt)})
# 
#   
  output$mytable1 <- renderDataTable({



    if(values$default==0){
      omw_inventory_2016[grep("Ethynyltrimethylsilane",omw_inventory_2016$Product.Name,ignore.case = T),.(Chemical=Product.Name,Manufacture=Manufacturer.Name,Catalog=Product.Code, Floor=Floor,Amount=Amount.per.Container,UOM=UoM )]
    }
    else{
      omw_inventory_2016[Product.Name==input$obs,.(Chemical=Product.Name,Manufacture=Manufacturer.Name,Catalog=Product.Code, Floor=Floor,Amount=Amount.per.Container,UOM=UoM)]
    }
  })


  output$mytable2 <- renderDataTable({ 



    if(values$default==0){
      omw_inventory_2016[grep("Ethynyltrimethylsilane",omw_inventory_2016$Product.Name,ignore.case = T),.(Chemical=Product.Name,Manufacture=Manufacturer.Name,Catalog=Product.Code, Floor=Floor,Amount=Amount.per.Container,UOM=UoM)]
    }
    else{
      omw_inventory_2016[Product.Code %chin% input$txt,.(Chemical=Product.Name,Manufacture=Manufacturer.Name,Catalog=Product.Code, Floor=Floor,Amount=Amount.per.Container,UOM=UoM)]
    }
  })

  output$mytable3 <- renderDataTable({



    if(values$default==0){
      omw_inventory_2016[grep("Ethynyltrimethylsilane",omw_inventory_2016$Product.Name,ignore.case = T),.(Chemical=Product.Name,Manufacture=Manufacturer.Name,Catalog=Product.Code, Floor=Floor,Amount=Amount.per.Container,UOM=UoM)]
    }
    else{
      omw_inventory_2016[MBC %chin% input$txt,.(Chemical=Product.Name,Manufacture=Manufacturer.Name,Catalog=Product.Code, Floor=Floor,Amount=Amount.per.Container,UOM=UoM)]
    }
  })

  output$mytable4 <- renderDataTable({



    if(values$default==0){
      omw_inventory_2016[grep("Ethynyltrimethylsilane",omw_inventory_2016$Product.Name,ignore.case = T),.(Chemical=Product.Name,Manufacture=Manufacturer.Name,Catalog=Product.Code, Floor=Floor,Amount=Amount.per.Container,UOM=UoM)]
    }
    else{
      omw_inventory_2016[Ingredient.CAS %chin% input$txt,.(Chemical=Product.Name,Manufacture=Manufacturer.Name,Catalog=Product.Code, Floor=Floor,Amount=Amount.per.Container,UOM=UoM)]
    }
  })




})
  • What exactly is your problem or question? It's about showing multiple pdf files? or just showing a table with the pdf files that the query returns? – Geovany Sep 26 '16 at 20:35
  • I would like to either show the pdf in a new tab that the query returns or a download link/button that downloads or opens the pdf the query returns in a new window. – Steve burnett Sep 27 '16 at 13:40
  • What is happening, and how is it different than what you think should be happening? Is the file name wrong? Is the link not generating correctly? Are the links right, but you want them to be clickable? – Mark Peterson Sep 27 '16 at 16:01
  • What I can do is show a specific ( by a direct file path ~/ directory/directory/some.pdf) pdf. But that is not what I want to do. In my datatable, I have full file paths to pdfs that correspond to specific chemicals. When a query is made, the corresponding file pdf file path is subseted and I would like that file path that was found to go to the UI and pop out in a new browser ( or download) after they click the button. As of now, it only works if I hard code the file path to a specific pdf... which is impossible to do with 10k pdf's – Steve burnett Oct 01 '16 at 18:23

0 Answers0