I'm trying to build a checklist that will show me different parts of my data in Rstudio using Shiny.
For example: If I check question A: Row 1:2 should show in my table If I check question B while A is still checked: I want to see row 1:2 & 5. If I uncheck question B but check question C while A is still checked: I want to see row 1:2 & 3:4
I made 2 versions but I'm stuck on both
Version 1 (were I'm having trouble with the if statements in the server):
if (interactive()) {
library(shiny)
library(readxl)
Sheet2 <- read_excel("Sheet2.xlsx")
Sheet3 <- read_excel("Sheet3.xlsx")
Sheet4 <- read_excel("Sheet4.xlsx")
ui <- fluidPage(
title = "Checklist",
sidebarLayout(
sidebarPanel(
checkboxInput(inputId = "A",
label = strong("A"),
value = FALSE),
conditionalPanel(condition = "input.A == true",
checkboxInput(inputId = "B",
label = strong("B"),
value = FALSE)),
checkboxInput(inputId = "C",
label = strong("C"),
value = FALSE)
),
mainPanel(
tabsetPanel(
id = 'dataset',
tabPanel("Sheet2", DT::dataTableOutput("mytable1")),
tabPanel("Sheet3", DT::dataTableOutput("mytable2")),
tabPanel("Sheet4", DT::dataTableOutput("mytable3"))
)
)
)
)
server <- function(input, output) {
output$mytable1 <-
DT::renderDataTable({
if (input$A){
DT::datatable(Sheet2[1:2,])}
if (input$C){
DT::datatable(Sheet2[3:4,])}
if (input$B){
DT::datatable(Sheet2[5,])
}
})
output$mytable3 <-
DT::renderDataTable({if ((input$A)){
DT::datatable(Sheet3[3:4,])}
})
}
shinyApp(ui, server)
}
And version 2 (were i cant add multiple rows to my groupinput):
if (interactive()) {
library(shiny)
library(readxl)
Sheet2 <- read_excel("Sheet2.xlsx")
Sheet3 <- read_excel("Sheet3.xlsx")
Sheet4 <- read_excel("Sheet4.xlsx")
B3 <- 3:4
ui2 <- fluidPage(
title = "M&A Checklist",
mainPanel(
tabsetPanel(
id = 'dataset',
tabPanel("Sheet1", checkboxGroupInput(inputId = "show_vars",
label = "Questions:",
choiceNames = c("AAAAAAAAAA","BBBBBBBBBB","CCCCCCCCCCC"),
choiceValues = c("1","B3","5") )),
tabPanel("Sheet2", DT::dataTableOutput("mytable1")),
tabPanel("Sheet3", DT::dataTableOutput("mytable2")),
tabPanel("Sheet4", DT::dataTableOutput("mytable3"))
)
)
)
server2 <- function(input, output) {
# choose columns to display
output$mytable1 <- DT::renderDataTable({
DT::datatable(Sheet2[input$show_vars,])
})
# sorted columns are colored now because CSS are attached to them
output$mytable2 <- DT::renderDataTable({
DT::datatable(Sheet3[input$show_vars,])
})
# customize the length drop-down menu; display 5 rows per page by default
output$mytable3 <- DT::renderDataTable({
DT::datatable(Sheet4[input$show_vars,] )
})
}
shinyApp(ui2, server2)
}
Any suggestions, on how this can be done efficiently?
Aucun commentaire:
Enregistrer un commentaire