jrzelling jrzelling - 3 months ago 28
R Question

Sys.info() not displaying in dashboardbody box

I'm trying to display the output of Sys.info() inside of a box(), but all it is displaying is one word "Darwin".

If I do

str(Sys.info())
I get

Named chr [1:8] "Darwin" "15.5.0" ...
- attr(*, "names")= chr [1:8] "sysname" "release" "version" "nodename" ...


So how can I display this as a block of text in a box? Should it be called in the server code and displayed in a textOutput instead?

Here is the dashboardBody code block which is in
ui.R
it is in a shinyUI(dashboardPage(...)):

dashboardBody(
fluidRow(
box(
title = "Time and Date",
status = "primary",
solidHeader = TRUE, width = 4,
"Time: ", Sys.time(), br(),
"Date: ", Sys.Date(), br(),
"Time Zone: ", Sys.timezone(), br(),
Sys.info(), br()
)
)
)


server.R is just empty:

shinyServer(function(input, output) {

})

Answer

Did you see the warning?

Warning in charToRaw(enc2utf8(text)) : argument should be a character vector of length 1 all but the first element will be ignored

Use this instead:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
    dashboardHeader(),
    dashboardSidebar(),
    dashboardBody(
        box(textOutput("sys_info")),
        box(tableOutput("sys_info2"))
    )
)

server <- function(input, output) {


    output$sys_info <- renderText({
        a <- Sys.info()
        a
    })

    output$sys_info2 <- renderTable({
        a <- data.frame(Sys.info())
        a
    })

}

shinyApp(ui, server)
Comments