【问题标题】:How to print the summary of a variable in R shiny?如何在 R Shiny 中打印变量的摘要?
【发布时间】:2018-06-14 22:36:39
【问题描述】:

我希望基于客户可以选择的selectInput(),将所选变量的摘要打印在一个框中。我的 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)
})

【问题讨论】:

  • 选择只是表示,应该用于检索数据集的一部分,因此对它们进行总结没有意义。查看here了解更多详情。
  • 什么样的总结?为什么你的方法不起作用?怎么了?
  • @A.Suliman 谢谢!但是你知道我该如何解决我的问题吗?
  • @phalteman 我得到了这个:Length Class Mode 1 character character
  • "InformedFull", .... 等应该代表可以汇总的数据或变量。由于这些只是名称,请在 R 中尝试 summary("InformedFull")

标签: r variables printing shiny summary


【解决方案1】:

如 cmets 所示,summary 返回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)

这是你想做的吗?

【讨论】:

  • Aurelien 你真是个天才!谢谢你的兄弟,这正是我正在寻找的!
猜你喜欢
  • 2021-06-18
  • 2017-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-21
  • 2021-02-15
  • 1970-01-01
相关资源
最近更新 更多