0

server code:

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)

The data filtering runs fine on its own however, it is not passing through the inputs correctly? It has to be something surrounding how we are structuring the reactive function. Could it have anything to do with using multiple tabs? Thank you.

  • Please provide a reproducible example. See https://stackoverflow.com/questions/48343080/how-to-convert-a-shiny-app-consisting-of-multiple-files-into-an-easily-shareable – MLavoie Mar 07 '18 at 10:16

1 Answers1

1

state_cast is not used anywhere and shouldn't really exist. It looks like it's being abused as a side-effect-only function. Just move its contents into renderPlot().

Additionally, you have a silver <- silver that doesn't seem to do anything.

I also recommend you use the Reindent Lines and Reformat Code buttons, because the indentation in the state_cast makes it a bit difficult to read.