0

There are only 4 languages here, so this is definitely not a duplicate of this

I've updated all my packages; this is not a duplicate of this or any of the other questions which suggest the answer is updating packages.


This is a pretty simple graph:

  ggplot(data=sounds, aes(x=phrase, y=score)) +
      geom_bar(stat="identity") +
      facet_grid(. ~ language, scales="free_x")

In Shiny, we'd have something like:

ui <- fluidPage(
  titlePanel("Title"),
  sidebarLayout(
    sidebarPanel(
      selectInput(
          "facet_on",
          label="Split graphing by...",
          choices = list(
              `Language` = "language",
              `Server` = "server",
          )     
      )
    ),
    mainPanel(
        plotOutput("languageMap")
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
  output$languageMap <- renderPlot({
      ggplot(data=sounds, aes(x=phrase, y=score)) +
          geom_bar(stat="identity") +
          facet_grid(. ~ input$facet_on, scales="free_x")
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

The problem is that the first example renders exactly as it should. There are multiple different facets, each representing a particular language, whose title is said language.

When I attempt this on Shiny, on the other hand, there is always one large facet, and said facet's title is the appropriate varaible—but the data doesn't actually facet out into its individual grids. The graph doesn't change at all, but, clearly, it's getting the appropriate variable from the choice selected and using it somewhere, since the facet label is changing to the variable passed to it.

Has anyone encountered this before?

AmagicalFishy
  • 1,249
  • 1
  • 12
  • 36
  • Have you looked at [this question/answer](https://stackoverflow.com/questions/21588096/pass-string-to-facet-grid-ggplot2)? I'm guessing the problem has to do with passing the facet variable as a string. – aosmith Jun 05 '18 at 16:23
  • @aosmith Wow. It *still* had nothing to do with Shiny! If you make your comment an answer, I'll gladly accept it – AmagicalFishy Jun 05 '18 at 16:30

0 Answers0