The issue is that you have to tell ggplot that your input
s are names of variables in your dataset. This could be achieved e.g. by making use of the .data
pronoun, i.e. instead of using input$x
which is simply a string use .data[[input$x]]
which tells ggplot that by input$x
you mean the variable with that name in your data:
As you provided no data I could not check but this should give you the desired result:
library(shiny)
library(ggplot2)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput(inputId = "y",
label = "Y-axis:",
choices = c("P-value", "P-adjust"),
selected = "P-adjust"),
selectInput(inputId = "x" ,
label = "X-axis:",
choices = c("FC", "Mean_Count_PD"),
selected = "FC")
),
mainPanel(plotOutput(outputId = "scatterplot"))
))
server <- function(input, output) {
output$scatterplot <- renderPlot({
ggplot(data = mir, aes(.data[[input$x]], .data[[input$y]])) + geom_point()
})
}
shinyApp(ui, server)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…