【问题标题】:Variable names disappear when using summarytools::descr() with by() in Shiny app在 Shiny 应用程序中使用 summarytools::descr() 和 by() 时变量名消失
【发布时间】:2018-07-22 20:43:28
【问题描述】:

R-package summarytools 中的 descr() 函数为 R 中的数值数据生成常见的集中趋势统计和离散度量。

当我在 Shiny 应用程序 中使用 descr() 和 by() 时,数据中包含的变量(特征)的名称会消失并且不显示。而是将名称替换为 Var1、Var2、Var3 等。

我真的不明白为什么当我在 Shiny 应用程序中实现这些代码时名称会消失(见下文)。 有什么想法吗?

# Install packages
source("https://bioconductor.org/biocLite.R")
biocLite("ALL")
biocLite("Biobase")
install.packages('devtools')
devtools::install_github('dcomtois/summarytools')

# Load packages
library(summarytools)
library(Biobase)
library(ALL) 

# Shiny Server
server <- function(input, output, session) {
  output$summaryTable <- renderUI({
    #-- Load the ALL data
    data(ALL)  
    #-- Subset
    eset_object <- ALL [1:3,] # choose only 3 variables 
    #-- The group of interest 
    eset_groups <-"BT"
    # print(rownames (eset_object)) # print variable names
    ALL_stats_by_BT <- by(data = as.data.frame(t(exprs(eset_object))), 
                          INDICES = (pData(eset_object)[,eset_groups]), 
                          FUN = descr, stats ="all", 
                          transpose = TRUE)

    view(ALL_stats_by_BT,
         method = 'render',
         omit.headings = FALSE,
         bootstrap.css = FALSE)
  })
}

# Shiny UI
ui <- fluidPage(theme = "dfSummary.css",
                fluidRow(
                  uiOutput("summaryTable")
                )
)

# Lauch
shinyApp(ui, server)

【问题讨论】:

    标签: r shiny summarytools


    【解决方案1】:

    标题会导致问题,所以你需要使用:

    view(ALL_stats_by_BT,
            method = 'render',
            omit.headings = TRUE, # not FALSE
            bootstrap.css = FALSE)
    

    另外,从 gitHub 安装最新版本(今天提交)以显示所有组(这是 descr() 的问题)

    devtools::install_github("dcomtois/summarytools")

    编辑

    我对其进行了更多研究,发现虽然这可行(我使用示例数据框进行简化)...

    server <- function(input, output, session) {
      library(summarytools)
    
      output$summaryTable <- renderUI({
    
        data(exams)
    
        stats_by_gender <- by(data = exams[,3:4],
                              INDICES = exams$gender, 
                              FUN = descr, stats ="all", 
                              transpose = TRUE)
    
        view(stats_by_gender,
             method = 'render',
             bootstrap.css = FALSE)
    
      })
    }
    

    ...这不会(意味着变量名丢失了):

    server <- function(input, output, session) {
      library(summarytools)
    
      output$summaryTable <- renderUI({
    
        data(exams)
    
        # this time using a temporary subsetted object     
        dat <- exams[,3:4]    
    
        stats_by_gender <- by(data = dat,
                              INDICES = exams$gender, 
                              FUN = descr, stats ="all", 
                              transpose = TRUE)
    
        view(stats_by_gender,
             method = 'render',
             bootstrap.css = FALSE)
    
      })
    }
    

    这与 summarytools 检索对象名称的方式有关,我需要进一步研究。

    【讨论】:

    • 我已按照您的指示进行操作,但我仍然遇到同样的问题!您有机会运行我的示例应用吗?
    • 好的,我看到了提示,但还没有解决方案...如果您将eset_object 加载到内存(全局环境)中,您会看到变量名吗?
    • 是的,如果将数据作为全局变量读入:eset_object
    • 我在项目页面打开了这个问题!
    • 我按照这些思路做了一些事情,它现在在 dev-current 分支中,但将成为下一个版本的一部分。更多详情请见github.com/dcomtois/summarytools/issues/26
    猜你喜欢
    • 1970-01-01
    • 2018-11-18
    • 2018-08-30
    • 2019-03-08
    • 2021-12-13
    • 1970-01-01
    • 2019-08-14
    • 2021-09-14
    • 1970-01-01
    相关资源
    最近更新 更多