简体   繁体   中英

Why renderTable() does not giving any output in shinyApp for selectInput items?

I want to display tabular data while input select entered in shinyUI.

Here is my code:

library(shiny)
library(shinydashboard)
library(dplyr)

ui <- shinyUI(
  dashboardPage(
    dashboardHeader(),
    dashboardSidebar(disable = TRUE),
    dashboardBody(
      selectInput("filt", "Datafiltered",
                  choices = unique(comor$DiagnosisProvided),
                  multiple = TRUE),
      tableOutput("tab1")
    )
  )
)

server <- shinyServer(
  function(input, output, session) {
    output$tab1 <- renderTable({
      apl <- data %>% filter(DiagnosisProvided == input$filt)
    })
  }
)

shinyApp(ui,server)

I am getting error "Result must have length 707, not 0" I would like to upload my data . Is there any link to upload my data?

Can anyone help me on renderTable() output?

The error is caused by data %>% filter(DiagnosisProvided == input$filt) , because input$filt is an empty array. You can reproduce this error by:

iris %>% filter(Sepal.Length == NULL) .... Result must have length 150, not 0

So check your unique(comor$DiagnosisProvided) it looks like it is empty. And then instead of using the == replace it by %in% :

data %>% filter(DiagnosisProvided %in% input$filt)

as you have not given any data sample to make it reproducible, I tried to built the same as per my understandings with IRIS Data. Hope this can solve your issue.

在此处输入图像描述

UI.R

library(shiny)
library(shinydashboard)
library(shinyglide)


dashboardPage(
   dashboardHeader(title = "Basic dashboard"),
   dashboardSidebar(
      sidebarMenu(
         menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
      )
   ),
   dashboardBody(
      useShinyalert(),
      tabItems(
         tabItem(tabName = "dashboard",
                 fluidRow(
                        column(3,
                               uiOutput("filter")
                               ),
                        column(9,
                               tableOutput("tab")
                               )
                        )
                 )
      )
   )
)

Server.R

library(shiny)
library(shinydashboard)
library(dplyr)


shinyServer(function(input,output){

####### Your data ######  

  data<-iris

 output$filter<-renderUI({
   selectInput("filter_select","Select Filter",choices = unique(data$Species))
 })

 output$tab<-renderTable({
   if(is.null(input$filter_select))
   {
     returnValue()
   }
   else
   {
     show_data<-data %>% filter(Species == input$filter_select)
     show_data
   }

 })


})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM