我在Shiny中遇到反應性問題。在我的用戶界面,我有R selectInput反應性問題
library(tidyverse)
library(shiny)
library(forcats)
ui <- fluidPage(
titlePanel(h1("Percent Cover")),
selectInput("selectInput", "Select Site", choices = c("A", "B", "C", "D")),
plotOutput("coverTypeBarChart", height = "600px")
)
這些對應於dataframes A,B,C,d,我在服務器的頂部讀入。
在我的服務器,我有:
colors <- c("red", "blue", "green", "purple")
reactive({
if (input$selectInput == "A")
{data <- A}
else if (input$selectInput == "B")
{data <- B}
else if (input$selectInput == "C")
{data <- C}
else if (input$selectInput == "D")
{data <- D}
})
data() <- na.omit(as.data.frame(data()$cover_group))
names(data()) <- c("tmp")
cover_group_factor <- as.factor(data()$tmp)
cover_group_factor <- fct_recode(cover_group_factor, OTHER = "E", OTHER = "F", OTHER = "G", OTHER = "H", OTHER = "I", OTHER = "J", OTHER = "K")
bar <- ggplot(data = data()) +
geom_bar(mapping = aes(x = cover_group_factor, y = ..count../sum(..count..)), fill = colors) + xlab("Cover Group") + ylab("Percent")
observe({
output$coverTypeBarChart <- renderPlot(bar)
})
}
我知道當我手動分配數據給任何值,並手動運行的代碼,我可以生產的情節,所以我知道這是一個反應性的問題。
謝謝。
我不能說太多,因爲我沒有數據框架的例子。但是,從我看到的情況來看,我看不到您已將任何東西附加到您的反應函數中。難道你需要說以下嗎? '數據< - 反應({ 如果(輸入$ selectInput == 「A」) {數據< - A} 否則如果(輸入$ selectInput == 「B」) {數據< - B} 如果(輸入$ selectInput ==「C」) { – p0bs