1

I have a shiny app in which I want to subset the datatable displayed based on the user Input in the sidebar. The issue is that as you will see the 3 last rows of my dataframe are not displayed at all while all rows are selected. I suspect that this happens because the "DCH" exists 3 times instead of one but I do not know what happens with "LDP".

DATA

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)

APP

#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)
  )
  }

1 Answer 1

1

When running your code, you will see the following errors in your console:

Warning in `==.default`(Database, input$base) :
  longer object length is not a multiple of shorter object length

To solve this, you should replace the line

a <- subset(db, Database == input$base)

with

a <- subset(db, Database %in% input$base)

Since you want to check if the values in the column are in the vector input$base, see here for the documentation of this operator. Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.