【问题标题】:Reactive not displaying appropriate graphs with working data filtering反应式不显示具有工作数据过滤的适当图表
【发布时间】:2018-08-15 09:30:25
【问题描述】:

服务器代码:

silver_state <- fread("./Data/silver_state.csv")
silver <- silver_state %>% arrange(total_drug_cost)

state_cast <- reactive({
 if(input$sort == "alphabetical"){
  silver <- silver
}
 else if(input$sort == "descending"){
  silver <- silver_state %>% arrange(desc(total_drug_cost))
  silver$nppes_provider_state <- factor(silver$nppes_provider_state, 
  levels = silver$nppes_provider_state[order(silver$total_drug_cost)])
}
 else{
  silver <- silver_state %>% arrange(total_drug_cost)
  silver$nppes_provider_state <- factor(silver$nppes_provider_state, 
  levels = silver$nppes_provider_state[order(silver$total_drug_cost)])
}

})


output$compare <- renderPlot({
 ggplot(silver) + 
  geom_bar(aes(x = nppes_provider_state, y = total_drug_cost), position 
= position_stack(reverse = TRUE), stat = "identity") +
  coord_flip() + 
  labs(title = "Total Cost of Drugs per State", y = "Total Drug Cost", 
x = "State")
})
}

shinyServer(my.server)

数据过滤本身运行良好,但是它没有正确地通过输入?它必须围绕我们如何构建反应函数。它与使用多个选项卡有什么关系吗?谢谢。

【问题讨论】:

标签: shiny shiny-server reactive


【解决方案1】:

state_cast 不在任何地方使用,也不应该真正存在。看起来它被滥用为仅具有副作用的功能。只需将其内容移至renderPlot()

此外,您还有一个 silver &lt;- silver,它似乎什么也没做。

我还建议您使用 Reindent LinesReformat Code 按钮,因为 state_cast 中的缩进使其有点难以阅读。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 2016-01-06
    • 1970-01-01
    • 2022-06-24
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    相关资源
    最近更新 更多