Is it possible to print on a physical receipt printer from a shiny app?

Hello everybody,

I'm wondering if someone has a pointer for me to investigate this topic, I'm interested in implementing receipt printing on a shiny app but I haven't managed to find anything about this on the internet. Does anybody know if this is even possible to implement?

I'm playing with the idea of developing a Point Of Sale (POS) on a Shiny App to use on a tablet, all the other needed functionalities are fairly easy to implement I can even report the emitted receipts to my country's tax authority trough an API but a physical receipt representation to hand to the client is the only functionality I'm missing.

This is a very silly app but it does print a file. It allows selecting from a set of file names, then clicking the Write button writes the unaltered file out to the app's directory and then clicking Print prints that file. I am using a Linux system, so the print command is lp. I am not sure how to do that on Windows or a Mac.

library(shiny) #  Shiny web app

ui <- fluidPage(fluidRow(selectInput("TheFile", "File", 
                                     choices = c("csv1.csv", "csv2.csv", "Dummy.csv"))),
                fluidRow(actionButton("button1", label = "Write")),
                fluidRow(actionButton("button2", label = "Print"))
              )

server <- function(input, output, session) {
  
  myCSV <- reactive({
    read.csv(input$TheFile)
  })
  
  observeEvent(input$button1, {
    write.csv(myCSV(), "WrittenFile.csv")
  })
  observeEvent(input$button2, {
    system2(command = "lp", "WrittenFile.csv")
  })
  
}

# run the app
shinyApp(ui, server)

The system call would only work if the printer is connected to the server so I don't think it is a practical solution, I would need to be able to print on a printer that is connected to the clients system, ideally a receipt printer connected to an android tablet via Bluetooth or wifi.

On the client side you have a browser. Can you print a PDF or HTML page from the browser on the receipt printer?

Trying to find out, I discovered that Epson receipt printers support driverless printing through a JavaScript library and also by sending XML or JSON data to the printer, so it might be possible to do it using httr. Now I have a ton of technical manuals to read to find out how.

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.