Question

I am trying to show a histogram based the selection from a selectInput. The output should be hist(dataframe$feature1) depending on what feature they choose, but nothing is showing. Here is my code.

ui.R

selectInput("variableFeat", "Choose Feature", c("feature1", "feature2", "feature3"))

server.R

 output$feature <- reactive({

    dataframe$input$variableFeat


})


output$hist <- renderPlot({

    hist(feature(), main="Histogram of Selected Feature", xlab="Selected Feature", ylab="Frequency", col="orange")

})
Was it helpful?

Solution

To render a histogram, create the vector of values first, based on user input then use if statements to choose which feature to view:

server.R

output$hist <- renderPlot({

   vectorOfValues1 <- dataFrame$FEATUREtoPLOT1
   vectorOfValues2 <- dataFrame$FEATUREtoPLOT2


if (input$variableFeat == "Choice1") {

    hist(vectorOfValues1}

}

if (input$variableFeat == "Choice2") {

    hist(vectorOfValues2}

}}

})

ui.R

outputPlot("hist")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top