【问题标题】:How to use the results of a reactive expression in an output如何在输出中使用反应式表达式的结果
【发布时间】:2020-09-03 05:11:10
【问题描述】:

我正在尝试构建一个闪亮的应用程序来监控我在主机上运行的容器,这是我迄今为止所尝试的。问题是如何在主面板中显示输出,在这种情况下(docker ps -a)内容?我是 Rshiny 的新手,非常感谢任何帮助!

library(shiny)
library(ssh)    

ui <- fluidPage(
    titlePanel("Dashboard"),
    sidebarLayout(
      sidebarPanel(
        actionButton("bttn", "Click")
      ),
      mainPanel(
        h1("Running containers"),
        textOutput("dispContainers")
      )
    )
  )

# Define server logic
server <- function(input, output, session) {
 
    session <- ssh_connect("jeroen@dev.opencpu.or")
      observeEvent(input$bttn, {
      ssh_exec_wait(session, command = 'docker ps -a')
    
  })
  
}

# Run the application 
shinyApp(ui, server)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您可以使用另一个 ssh_exec_internal 来收集您的 docker 命令的输出。比如:

    server <- function(input, output, session) {
      session <- ssh_connect("jeroen@dev.opencpu.or")
      text_output <- reactiveVal("")
      observeEvent(input$bttn, {
        response <- ssh_exec_internal(session, command = 'docker ps -a')
        text_output(rawToChar(response$stdout))
      })
      output$dispContainers <- renderText(text_output())
    }
    

    您可能还想将textOutput 切换到verbatimTextOutput 以获取您在终端中看到的文本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多