r - 初学者 - 我想在 R 中的 Shiny 上制作 ggplot,但我不知道我在哪里犯了错误
问题描述
我在 R 中使用 Shiny 来制作两个不同的选项卡。我认为一个选项卡是一个好主意,可以制作一个摘要选项卡,另一个选项卡用于绘图。我想为用户提供 x、y 和颜色部分的选择...当我完成 ggplot 部分的部分时,该图未按预期显示。请帮我解决我在哪里犯了错误,请帮助我理解它。
谢谢你。
# ui.R
library(shiny)
library(ggplot2)
library(plyr)
library(dplyr)
data(mtcars)
new_mtcars <- mtcars %>%
select(wt,mpg,cyl,vs,am,gear,carb)
# Define UI for an application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("prac"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("xvalue","Please Choose X Value : ", c("wt","mpg")),
selectInput("yvalue","Please Choose Y Value : ", c("wt","mpg")),
selectInput("color","Please Choose color Value : ", choices = c("cyl","vs","am","gear","carb"))
),
mainPanel(
tabsetPanel(#tabPanel("Information",tableOutput("info")),
tabPanel("Summary",tableOutput("summary")),
tabPanel("Comparison",plotOutput("plot")))
)
)
# Show a plot of the generated distribution
))
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
df_sub <- reactive({
new_mtcars[,c(input$xvalue,input$yvalue,input$color)]
})
output$plot <- renderPlot({
category <- input$color
ggplot(df_sub(), aes(input$xvalue,input$yvalue)) +
geom_point(aes_(color = as.name(category)),size = 3) +
geom_smooth(method = "lm")
})
})
解决方案
推荐阅读
- python - 自版本 2.0.0 以来散景图已损坏
- html - 只有 CSS 的响应式步进器
- java - 我得到 org.json.JSONException: No value for an item ,它存在于我的 json 数组中
- r - 如何将数据集转换为特定类型的矩阵?(RStudio)
- scala - 在scala中使用_._2时如何在过滤谓词中使用OR运算符
- vba - 导出到 CSV - 标题为 TEXT 而不是 GENERAL
- android - java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“int android.view.View.getImportantForAccessibility()”)
- colorbar - 如何将水平颜色条的标签放在matplotlib的颜色条下方?
- javascript - 在图片中写入实时文本(在图片中实时渲染文本)
- php - MySQL:一对多关系表,将所有选择命令返回到单个 json 列