Reputation: 401
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 ?
Upvotes: 1
Views: 322
Reputation: 1075
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)
Upvotes: 0
Reputation: 978
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
}
})
})
Upvotes: 1