如何在 R shiny 中打印变量的摘要?

How to print the summary of a variable in R shiny?

我希望基于客户端可以 select 的 selectInput(),selected 变量的摘要将打印在一个框中。我的 ui.R 代码是:

box(
  title = "Informed Investor", 
  status = "primary", 
  solidHeader = TRUE,
  width = 6,
  selectInput("informedDset", label="Select Category", choices = list("Informed Full" = "InformedFull", "Informed Fact" = "InformedFact", "Informed Fact Positive" = "InformedFact.Pos", "Informed Fact Negative" = "InformedFact.Neg", "Informed Emotions" = "InformedEmotions", "Informed Emotions Fact" = "InformedEmotionsFact"), selected = "Informed Full")
), 

box(
  title = "Data Table", 
  status = "warning", 
  solidHeader = TRUE,
  width = 6,
  height = 142,
  verbatimTextOutput("summaryDset")
)

我的 server.R 代码:

output$summaryDset <- renderPrint({
   summary(input$informedDset)
})

如注释中所示,summary returns Length Class Mode 1 character character 因为 input$informedDset 是一个字符串。 如果您想提取数据集中一个选定变量的摘要,您可以在下面使用 iris 数据集找到一个可重现的示例:

library(shiny)
library(shinydashboard)

ui=fluidPage(

 box(title = "Informed Investor", 
  status = "primary", 
  solidHeader = TRUE,
  width = 6,
  selectInput("informedDset", label="Select Category",
          choices = list("Sepal.Length"="Sepal.Length",
                         "Sepal.Width"="Sepal.Width",
                         "Petal.Length"="Petal.Length",
                         "Petal.Width"="Petal.Width",
                         "Species"="Species"), selected = "Sepal.Length")),

box(
 title = "Data Table", 
 status = "warning", 
 solidHeader = TRUE,
 width = 6,
 height = 142,
 verbatimTextOutput("summaryDset")))


server = function (input,output){
 output$summaryDset <- renderPrint({
 summary(iris[[input$informedDset]]) 
})}

shinyApp(ui, server)

这是你想做的吗?