0
votes

I have a Shiny app that's doing with a server and ui function like this:

df<- read_csv(path_here)

ui <- fluidPage(
  
  # App title ----
  titlePanel("Histograms!"),
  
  # Sidebar layout with input and output definitions ----
  sidebarLayout(
    
    # Sidebar panel for inputs ----
    sidebarPanel(
      
      checkboxGroupInput("Company", 
                         "Company", 
                         choices = unique(df$Company)
                         ),
      checkboxGroupInput("predicted_condition", 
                         "Predicted Condition", 
                         choices = unique(df$Predicted.Condition)
      )
      ),
    
    # Main panel for displaying outputs ----
    mainPanel(
      
      # Output: Histogram ----
      plotOutput(outputId = "distPlot")
      
    )
  )
)  
server<- function( input, output, session){
  reactive_data <- reactive({
    df %>% 
      filter(Company %in% input$Company)%>%
      filter(Predicted.Condition %in% input$Predicted_Condition)%>%
      select(Predicted.Probability)
  })
  
  output$distPlot <- renderPlot({
    hist(reactive_data())
  })
}

Basically I'm making a histogram where the user can use check boxes called Company and Predicted_Condition. Their selections would filter the corresponding columns in my df, then I'd make a histogram of the probabilities left in the Predicted.Probability column.

However, when I run this I get an error that says x must be numeric even though I've checked that the Predicted.Probability column is numeric. Any suggestions on what to do here?

1
Perhaps you can share some sample data with dput() to help you. - YBS
select always returns a dataframe, use pull to get a vector. Without seeing example data, it's hard to tell where the breaks error comes from - starja
I ran dput on my Predicted.Probability column. The last few entries were: 0.000703995, 0.000594523, 0.000214589, 0.000145538, 0.00028317, 0.000564918, 0.000354667, 0.000280292, 0.000117386, 0.000207468, 0.000323793, 0.011153646) Running summary on the column yields a min of 0.0001 and a max of 1.0000, but I'm still getting invalid number of breaks error - lvnwrth

1 Answers

1
votes

It's hard to know without your data and your ui, but it seems like you are trying to make a histogram from a dataframe. Yes, your column may contain numeric values, but you are essentially filtering down to a dataframe with one column, not a numeric vector. Try this:

server<- function( input, output, session){
  reactive_data <- reactive({
    filtered_dat <- df %>% 
      filter(Company %in% input$Company)%>%
      filter(Predicted.Condition %in% input$Predicted_Condition)

    return(filtered_dat$Predicted.Probability))
  })
  
  output$distPlot <- renderPlot({
    hist(reactive_data())
  })
}