在 Shiny 应用程序中使用 summarytools::descr() 和 by() 时变量名称消失
Variable names disappear when using summarytools::descr() with by() in Shiny app
R 包中的 descr() 函数 summarytools 为 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)
标题有问题,所以你需要使用:
view(ALL_stats_by_BT,
method = 'render',
omit.headings = TRUE, # not FALSE
bootstrap.css = FALSE)
此外,安装 gitHub 的最新版本(今天承诺)以显示所有组(这是 descr()
版本 < 0.8.7 的问题)
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 检索 object 名称的方式有关,我需要进一步研究它。
R 包中的 descr() 函数 summarytools 为 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)
标题有问题,所以你需要使用:
view(ALL_stats_by_BT,
method = 'render',
omit.headings = TRUE, # not FALSE
bootstrap.css = FALSE)
此外,安装 gitHub 的最新版本(今天承诺)以显示所有组(这是 descr()
版本 < 0.8.7 的问题)
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 检索 object 名称的方式有关,我需要进一步研究它。