File input API to JSON FILE


#1

In the previous example, the csv file is input and the operation is performed. However, I used the json lite library to work with json files as input. The error is “‘con’ is not a connection”. I think it’s a problem because the file was not formatted properly during upload. Below is a test code that looks for someone to solve the problem.
code

## Only run examples in interactive R sessions
library(jsonlite)
library(shiny)
if (interactive()) {
  
  ui <- fluidPage(
    titlePanel("LoFi Performance of Analysis System"),
    sidebarLayout(
      sidebarPanel(
        fileInput("LoRa_EXP_Info_File", "Choose EXP Info", 
                  accept = c(
                    "application/json",
                    "text/comma-separated-values,text/plain",
                    ".json")
                  ),
        fileInput("LoRa_EXP_Result_File", "Choose EXP Result",
                  accept = c(
                    "text/json",
                    "text/comma-separated-values,text/plain",
                    ".json")
       ),
      tags$hr()
    ),
      mainPanel(
        textOutput("contents")
       
      )
    )
  )
  
  server <- function(input, output) {
    output$contents <- renderText({
      # input$file1 will be NULL initially. After the user selects
      # and uploads a file, it will be a data frame with 'name',
      # 'size', 'type', and 'datapath' columns. The 'datapath'
      # column will contain the local filenames where the data can
      # be found.
      inFile <- input$LoRa_EXP_Info_File
      
      # json_file <- "/Users/imjun-yeong/Desktop/lora_packet.json"
       if (is.null(inFile))
         return(NULL)
      
       expData <- fromJSON(paste(readLines(inFile), collapse=""))
       print(expData)
      'test'
      
    })
  }
  
  
  
  shinyApp(ui, server)
}