Hi,
Relatively new to R and Shiny.
I'm not sure how to get a pure string from JSON file and I'd appreciate some help.
Here's a working example. I upload the JSON file at the bottom, then I want to present the Date and Server Name as line items. How do I remove the [1]
that proceeds each string? Also, is there an easy way to chomp \n
?
I've tried forcing as strings with this result (The "please help me remove the leading chr
" problem)
server.R:
library(shiny)
library(tidyverse)
library(tidyjson)
library(jsonlite)
shinyServer(function(input, output) {
diagnostic_details <- reactive ({
req(input$file)
jsonlite::fromJSON(input$file$datapath)
})
header <- reactive ({
req(diagnostic_details())
header_details <- pluck(diagnostic_details(), "header", 1)
header_details
})
output$date <- renderPrint({
h <- str_split_fixed(header(),'\\n',3)
print(h[[1]])
#h[[1]]
#str(h[[1]])
})
output$servername <- renderPrint({
h <- str_split_fixed(header(),'\\n',3)
print(h[[3]])
#h[[3]]
#str(h[[3]])
})
})
ui.R:
library(shiny)
shinyUI(fluidPage(
titlePanel("TEST"),
sidebarLayout(
sidebarPanel(
fileInput("file", label = h3("File input")),
hr(),
fluidRow(column(12,verbatimTextOutput("value"))),
hr(),
fluidRow(column(4, "Date"), column(8,textOutput("date"))),
fluidRow(column(4, "Server Name"), column(8, textOutput("servername"))),
),
mainPanel(),
),
))
test.json
{
"header": "Tue 24 Jan 13:24:09 AEDT 2021\nServer name:\nMyHostName\n",
"Detect OS": "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=21.04\nDISTRIB_CODENAME=hirsute\nDISTRIB_DESCRIPTION=\"Ubuntu 21.04\""
}