r - 我无法让我的 Shiny (in R) 应用程序散点图在窗口中呈现
问题描述
不断出现的错误是Error in output$barchart <- renderPlotly({ : object 'output' not found
我不太确定这里出了什么问题。我对这个项目有点不知所措。
我正在使用 dplyr 中预加载的 Midwest 数据框做这个项目
我愿意接受任何人对此进行的任何编辑。Aghghhhgghgh helpppp 哈哈
到目前为止,这是我的两个文件(server.R 和 ui.R)
服务器:
library(dplyr)
library(tidyr)
library(stringr)
library(lintr)
library(shiny)
library(ggplot2)
library(knitr)
library(tidyverse)
library(operators)
library(magrittr)
server <- function(input, output) {
output$barchart <- renderPlotly({
scatter <- ggplot(data = midwest,
mapping = aes(x = percollege, y = percpovertyknown)) +
geom_point(aes(fill = state, size = popdensity), shape = 21, color = "white") +
# geom_smooth(aes(x = percollege, y = percpovertyknown)) +
labs(
x = "Percent with college education",
y = "Poverty rate",
title = "Midwest Data",
subtitle = "States with higher college education rates tend to have lower poverty rates") +
scale_color_brewer(palette = "Set1") +
scale_size(range = c(0, 12)) +
guides(size = guide_legend(override.aes = list(col = "black")),
fill = guide_legend(override.aes = list(size = 5))) +
theme_bw()
chartly <- ggplotly(scatter)
return(chartly)
})
}
用户界面:
library(shiny)
library(ggplot2)
library(dplyr)
library(plotly)
library(lintr)
page_one <- tabPanel(
"Introduction",
ui <- fluidPage(
# START OF PAGE 2 / CHART---------------------------------
# Inputting Panel
page_two_sidepanel <- sidebarPanel(
checkboxGroupInput("checkGroup",
label = h3("Select State"),
choices = list("Illinois" = "IL",
"Indiana" = "IN",
"Minnesota" = "MN",
"Ohio" = "OH",
"Wisconsin" = "WN"),
selected = "IL"
)
),
page_two_mainpanel <- mainPanel(
h2("Barchart Comparison by Income Classification"),
plotOutput(
outputId = "barchart"
)
)
解决方案
我无法重现您遇到的错误,代码运行得很好。为简单起见,我将代码制作成单个 app.R 文件。我发现的一个问题是它应该是 plotlyOutput 而不是 plotOutput。
library(dplyr)
library(tidyr)
library(stringr)
library(lintr)
library(shiny)
library(ggplot2)
library(knitr)
library(tidyverse)
library(operators)
library(magrittr)
library(plotly)
ui <- fluidPage(
checkboxGroupInput("checkGroup",
label = h3("Select State"),
choices = list("Illinois" = "IL",
"Indiana" = "IN",
"Minnesota" = "MN",
"Ohio" = "OH",
"Wisconsin" = "WN"),
selected = "IL"
),
plotOutput(
outputId = "barchart"
)
)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
checkboxGroupInput("checkGroup",
label = h3("Select State"),
choices = list("Illinois" = "IL",
"Indiana" = "IN",
"Minnesota" = "MN",
"Ohio" = "OH",
"Wisconsin" = "WN"),
selected = "IL"
)
),
mainPanel(
plotlyOutput("barchart")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$barchart <- renderPlotly({
scatter <- ggplot(data = midwest,
mapping = aes(x = percollege, y = percpovertyknown)) +
geom_point(aes(fill = state, size = popdensity), shape = 21, color = "white") +
# geom_smooth(aes(x = percollege, y = percpovertyknown)) +
labs(
x = "Percent with college education",
y = "Poverty rate",
title = "Midwest Data",
subtitle = "States with higher college education rates tend to have lower poverty rates") +
scale_color_brewer(palette = "Set1") +
scale_size(range = c(0, 12)) +
guides(size = guide_legend(override.aes = list(col = "black")),
fill = guide_legend(override.aes = list(size = 5))) +
theme_bw()
chartly <- ggplotly(scatter)
return(chartly)
})
}
# Run the application
shinyApp(ui = ui, server = server)
推荐阅读
- node.js - 错误接收器-[onTurnError]:TypeError:无法读取未定义的属性“getTeamDetails”
- c# - 从 C# 中杀死一个远程 linux 进程
- selenium - 线程“主”org.openqa.selenium.NoAlertPresentException 中的异常:尝试使用 Selenium 和 Java 解除警报时没有此类警报
- azure - ISTIO 内部流量路由是否可以使用自定义网关?
- typescript - 这个类型声明中的 { 0: T } 是什么意思?
- python-3.x - 如何“pip安装rdpy”
- salesforce - SOQL:即使零行满足查询,有没有办法返回列标题
- angularjs - Ag-grid 中 onCellValueChanged 和 Tab 键的问题
- cuda - 图灵架构中异步引擎计数的说明
- lex - 指数的 Lex 解析