0

I am using Shiny for the first time in R. I am using the following code to generate my app:

library(shiny)
library(ggplot2)
library(tidyverse)

feature.options <- c("UTR length", "total RBP", "Counts AREs", "Codon Optimality", "m6A enrichment")

ui <- fluidPage(
  titlePanel("Feature distributions"),
  theme = shinythemes::shinytheme("sandstone"),
  sidebarLayout(
    sidebarPanel(
  
      selectInput("feature", "Which feature do you want to analyze?", choice = feature.options)
      
    ),
    
  mainPanel(
      
    plotOutput("plot")
    
  )
  )
)
server <- function(input, output, session) {
  
  
  
  output$plot <- renderPlot({
    
       Matrix.PV.mRNA.destab %>%
              group_by(status) %>%
              ggplot( aes(x = input$feature, fill = status)) + 
                geom_density(color = "black") +
                theme_classic() +
                theme(axis.text = element_text(size = 14),
                      axis.title = element_text(size = 14))
  })

  }

shinyApp(ui, server)

The result I get is this (The selectInput works out just fine, don't know why it isn't showing on the image I uploaded):

enter image description here

When I run the ggplot code separately I get this (which is what I want): enter image description here

Would you know why the ggplot chunk isn't working? I tried storing input$variable on an object to run through the ggplot function but didn't work. I also tried to run aes_string(), without success.

5
  • 3
    Try ggplot( aes(x = .data[[input$feature]], fill = status)) Commented Mar 4, 2024 at 21:25
  • @MrFlick, that is not a canonical fix to the problem; per ggplot2.tidyverse.org/articles/ggplot2-in-packages.html, the preference is to use aes(x=.data[[input$..]]), not symbols. (Of course, can we trust the docs? ggplot2-book.org/… still recommends the long-deprecated aes_(..).) Commented Mar 4, 2024 at 21:28
  • This is certainly a dupe, but I feel like we need a better dupe resolution ... Commented Mar 4, 2024 at 21:28
  • I saw the edits, I agree. Commented Mar 4, 2024 at 21:34
  • @YBS solution worked very well for it. Bravo!! Commented Mar 4, 2024 at 21:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.