我有一个闪亮的应用程序,我想根据侧边栏中的用户输入对显示的数据表进行子集化。问题是,正如您将看到的那样,当选中所有行时,数据框的最后3行根本不显示。我怀疑这是因为“ DCH”存在3次而不是3次,但我不知道“ LDP”会发生什么。
Database<-c("Composite","DB","TC","RH","DGI","DCH","DCH","DCH","LDP")
Organism<-c("Human","Human","Human","Human","Human","Human","Mouse","Rat","Human")
Unique_Drugs<-c(12672,5130,1425,3090,6100,2019,250,736,1182)
Unique_Targets<-c(3987,2175,842,2308,2413,1441,198,327,702)
Mean_S.D.Targets_per_Drug<-c("5.87 ± 6.72","2.60 ± 6.87","2.28 ± 3.76","3.29 ± 5.03","3.60 ± 5.21","6.28 ± 14.29"
,"1.92 ± 1.83"
,"4.11 ± 5.32"
,"4.27 ± 8.25"
)
Mean_S.D.Drugs_per_Target<-c("11.63 ± 15.59",
"12.52 ± 23.93",
"10.71 ± 8.37",
"12.98 ± 17.57",
"23.44 ± 25.65",
"13.87 ± 34.23",
"8.20 ± 18.44",
"14.82 ± 9.36",
"17.43 ± 9.34"
)
Unique_Drug_Target_Associations<-c(
45276,
14598,
3599,
12439,
23048,
13872,
594,
2876,
3915)
db<-data.frame(Database,Organism,Unique_Drugs,Unique_Targets,Mean_S.D.Drugs_per_Target,Mean_S.D.Targets_per_Drug, Unique_Drug_Target_Associations)
#ui.r
library(shiny)
library(shinydashboard)
library(DT)
ui <- dashboardPage(
dashboardHeader(
title = "Stats Table"
),
dashboardSidebar(
uiOutput("dbase")
),
dashboardBody(
DTOutput('tbl')
)
)
#server.r
library(shiny)
library(shinydashboard)
library(DT)
server <- function(input, output,session) {
output$dbase<-renderUI({
checkboxGroupInput("base", label = "Specify dataset(s)",
choices = list("Composite","DB","TC","RH","DGI","DCH","LDP"),
selected = c("Composite","DB","TC","RH","DGI","DCH","LDP")
)
})
df_subset <- reactive({
a <- subset(db, Database == input$base)
return(a)
})
output$tbl = renderDT(
df_subset(), options = list(lengthChange = FALSE)
)
}
答案 0 :(得分:1)
运行代码时,您将在控制台中看到以下错误:
Warning in `==.default`(Database, input$base) :
longer object length is not a multiple of shorter object length
要解决此问题,您应该替换行
a <- subset(db, Database == input$base)
使用
a <- subset(db, Database %in% input$base)
由于您要检查列中的值是否在向量input$base
中,因此请参阅here,以获取该运算符的文档。希望这会有所帮助!