Histogram not showing when based on reactive user input Shiny (R) [closed]

StackOverflow https://stackoverflow.com/questions/23555556

  •  18-07-2023
  •  | 
  •  

Frage

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")

})
War es hilfreich?

Lösung

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")
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top