闪亮的不显示ggplot数据 [英] Shiny not displaying ggplot data

查看:46
本文介绍了闪亮的不显示ggplot数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是处理光泽包装的新手.我正在尝试使用它来显示ggplot2图.我的代码没有错误,但是数据点未出现在图形上.当我从ui中选择变量时,轴标签会相应更改,但数据不会添加到绘图中.

I am new to working with shiny package. I am trying to use it to display a ggplot2 graph. I get no errors with my code, however data points are not appearing on the graph. When I select the variables from ui, the axes labels changes accordingly but the data is not added to the plot.

谢谢

代码:

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(input$x,input$y)) + geom_point()
     })
 }

推荐答案

问题是您必须告诉ggplot您的 input s是数据集中变量的名称.例如,这可以实现.通过使用 .data 代词,即不要使用 input $ x ,它只是一个字符串,而是使用 .data [[input $ x]] 告诉ggplot,通过 input $ x 表示您在数据中具有该名称的变量:

The issue is that you have to tell ggplot that your inputs 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)

这篇关于闪亮的不显示ggplot数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆