我正在开展一个学校项目,其中有一些 dyplr 查询,我需要使用 Shiny 库使它们交互。现在我在 dyplr 中有一个查询,在那里我可以看到印度外卖餐厅每个国家的收入。我有以下查询:
```
df %>%
group_by(Origin, Jaar = year(Order.Date), Maand = month(Order.Date, label = TRUE), Kwartaal = quarter(Order.Date)) %>%
summarize(omzet = sum(regelomzet)) %>%
ggplot(aes(reorder(Origin, omzet), omzet)) +
facet_grid(~Jaar) +
geom_col() +
ggtitle("Omzet per land van herkomst") +
coord_flip() +
theme(axis.text.x = element_text(angle = 90))
```
This gives me the following output:
Now if I change the facet_grid to for example kwartaal
(quarters in a year) I get the following output:
Now I would like to apply this plot in a interactive Shiny app. i use the following code for this:
```
```{r}
library(shiny)
ui <- fluidPage(
titlePanel("Indian takeaway"),
navlistPanel("Kies een plot",
tabPanel("Omzet per land van herkomst",
selectInput(inputId = "Select_unit",
label = "Selecteer op basis van wat je de grafiek wilt zien",
choices = c("Jaar", "Kwartaal", "Maand"),
selected = "Jaar"
),
plotOutput(outputId = "plot3")
)
)
)
server <- function(input, output, session) {
output$plot3 <- renderPlot({
df %>%
group_by(Origin, Jaar = year(Order.Date), Maand = month(Order.Date, label = TRUE), Kwartaal = quarter(Order.Date)) %>%
summarize(omzet = sum(regelomzet)) %>%
ggplot(aes(reorder(Origin, omzet), omzet)) +
facet_grid(~input$Select_unit) +
geom_col() +
ggtitle("Omzet per land van herkomst") +
coord_flip() +
theme(axis.text.x = element_text(angle = 90))
})
}
shinyApp(ui, server)
```
Here I make a slicer and show the plot on the Shiny app. To change the facet_wrap I use the input function that is linked to the input box now if I change the variable in the input box I would expect it to show the graph like in the above two pictures.
Now if I start the shiny app you can see that there isn't any facet_grid in the first place not even on the variable that is standard. My question is why does it do this because I did include it in my query. Because I have no clue I don't know how I could fix this and already did google this but couldn't find anything helpfull