I'm trying to make an app with shiny
, when I run the app with the code below appears an error.
Error:
Warning: Error in : Problem with `filter()` input `..2`.
ℹ Input `..2` is `site == input$cueva`.
x Input `..2` must be of size 672 or 1, not size 0.
202: <Anonymous>
library(shiny)
library(shinyWidgets)
sampleTypeVector <- c("Tapete microbiano", "Estromatolito", "Sedimento", "Suelo")
caves <- c("Chimalacatepec", "Iglesia")
ui <- fluidPage(
titlePanel("Taxonomic composition"),
fluidRow(
column(4, " ",
pickerInput("sample.type", label = "Sample",
choices = sampleTypeVector,
multiple = TRUE,
options = pickerOptions(
actionsBox = TRUE
))),
column(8, " ",
pickerInput("cave", label = "Cave",
choices = caves,
multiple = TRUE,
options = pickerOptions(
actionsBox = TRUE
)))
),
fluidRow(
column(6, " ", label = "Barplot",
plotOutput("barplot", click = "plot_click"))
)
)
server <- function(input, output, session) {
data <- reactive({
phy1 %>%
filter(sampleType == input$sample.type, site == input$cave)
})
output$barplot <- renderPlot({
phylum_barplot(data(), sample, relativeAb, Phylum, colorsVector)#function which makes a barplot with ggpplot
})
}
shinyApp(ui = ui, server = server)
And if I select all the options, my plot appears with fewer bars than it should, like the image below. It should be 48.
I try to fix the error adding sum()
as I saw in other examples like this one: Getting error while using ggplot with r-shiny (Warning: Error in : Problem with filter()
input ..1
.). But when I add sum()
in filter()
appears the next error and my barplot doesn't appear.
Warning: Error in : Problem with `filter()` input `..1`.
ℹ Input `..1` is `sum(sampleType == input$tipo.muestra, site == input$cueva)`.
x Input `..1` must be a logical vector, not a integer.
202: <Anonymous>
And I don't know how to fix it.
My data are here: data_shiny.csv
Thank you very much for your time.
I recently posted a question similar to yours, and the solution was to use %in%
instead of ==
in filter()
. Maybe it solves your problem too.