Display plain text of string values in vector

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?

Screenshot 2021-10-15 155207

I've tried forcing as strings with this result (The "please help me remove the leading chr" problem)
Screenshot 2021-10-15 155609

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\""
}

Try using cat instead of print . Does that help?

1 Like

Yes, perfect. Thank you.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.