基于反应用户输入的直方图未显示Shiny(R)

时间:2014-05-09 02:06:44

标签: r shiny

我试图根据selectInput中的选择显示直方图。输出应该是hist(dataframe $ feature1),具体取决于他们选择的功能,但没有显示任何内容。这是我的代码。

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

})

1 个答案:

答案 0 :(得分:0)

要渲染直方图,首先根据用户输入创建值向量,然后使用if语句选择要查看的要素:

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