我在 Shiny 中的反应性有问题。在我的用户界面中,我有
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")
)
这些对应于我在服务器顶部读取的数据帧 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)
})
}
我知道当我手动将数据分配给任何值并手动运行代码时,我可以生成绘图,所以我知道这是一个反应性问题。
谢谢。