0

My problem doesn't seem like it should be complicated, but I believe that the reactive() within the shiny package is preventing me from adding conditional colouring to the type= "l" line within my renderPlot().

library(shiny)
library(ggplot2)

# Define server logic for random distribution application

shinyServer(function(input, output) {

  sliderValues <- reactive ({
    #compose data frame
    ws<- as.numeric  (c(0:input$sws))
    df<-data.frame(
      WindSpeed = as.numeric  (c(ws)
      ),
      CBH = as.numeric (c(input$sCBH)
      ),
      FFMC = as.numeric (c(input$sFFMC)
      ),
      DC = as.numeric  (c(input$sDC)
      ),
      PCFI = as.numeric  (c((exp(-66.62+(-0.993*input$sCBH)+(0.568*ws)+(0.671*input$sFFMC)+(0.018*input$sDC)))/(1+(exp(-66.62+(-0.993*input$sCBH)+(0.568*ws)+(0.671*input$sFFMC)+(0.018*input$sDC)))))
      )

    )

  })

  #Show the values using an HTML table
  output$summary <- renderPlot ({
    plot(sliderValues()$WindSpeed, sliderValues()$PCFI, col =ifelse(sliderValues()$PCFI <0.5, 'green', 'red'),  type="l", lty = 2, ylim = c(0,1), xlab = "Windspeed 10 km/hr", ylab = "Probability of Crown Fire Initiation (%)")
  })  

  output$values <- renderTable({
    sliderValues()


  })

})
nrussell
  • 18,382
  • 4
  • 47
  • 60
AlphaKevy
  • 187
  • 2
  • 14
  • It's unclear what you are expecting. Your plot only has one line, so it will be colored by whatever the first value of `col` is. – NicE Mar 04 '16 at 16:26
  • @NicE ohh, I wasn't sure it is was possible to color code the top and bottom halves with 0.5 as the cutoff. I attempted to set the cutoff for slider()Values$PCFI at 0.5 along the y-axis, but it provides a very different graph than would be expected. Would you have any inclinations as to why that happens? This reactive function is a concept I've been struggling with. – AlphaKevy Mar 04 '16 at 16:31
  • Are you trying to do something like [this](http://stackoverflow.com/questions/7344018/plot-a-line-chart-with-conditional-colors-depending-on-values)? – NicE Mar 04 '16 at 16:37
  • Yea, I was just looking at that question. There must be something off when I call sliderValues()$PCFI as it transforms the smooth fitted line to something unexpected. But yea, that's exactly what I'd like the line to do, it's just transforming now for some unknown reason. – AlphaKevy Mar 04 '16 at 16:40

0 Answers0