r - 为什么我在尝试发布到 shinyapps 时会看到此错误?
问题描述
我正在尝试将带有以下数据的条形图发布到闪亮的应用程序上:
state mean_gain
1 Alabama 6.500000
2 Alaska 6.937931
3 Arizona 6.693750
4 Arkansas 7.306579
5 California 5.823729
6 Colorado 5.412308
7 Connecticut 6.422222
8 Delaware 8.725000
9 District of Columbia 3.700000
10 Florida 7.216176
11 Georgia 6.888750
12 Hawaii 6.166667
13 Idaho 7.000000
14 Illinois 7.932039
15 Indiana 7.683871
16 Iowa 7.487000
17 Kansas 8.300000
18 Kentucky 7.926446
19 Louisiana 8.629231
20 Maine 7.288235
21 Maryland 7.876000
22 Massachusetts 6.553333
23 Michigan 7.922619
24 Minnesota 6.918182
25 Mississippi 6.993976
26 Missouri 7.239655
27 Montana 6.114035
28 Nebraska 6.906383
29 Nevada 7.694444
30 New Hampshire 7.700000
31 New Jersey 7.304545
32 New Mexico 7.179412
33 New York 7.547619
34 North Carolina 6.391089
35 North Dakota 5.940741
36 Ohio 8.887640
37 Oklahoma 7.824359
38 Oregon 7.367568
39 Pennsylvania 7.082353
40 Rhode Island 7.683333
41 South Carolina 5.791489
42 South Dakota 5.277612
43 Tennessee 6.566667
44 Texas 7.543529
45 Utah 7.353333
46 Vermont 6.920000
47 Virginia 6.595556
48 Washington 7.332500
49 West Virginia 6.937500
50 Wisconsin 7.234247
51 Wyoming 7.254167
我用来发布到 shinyapps 的代码是:
用户界面:
ui <- fluidPage(
checkboxGroupInput("select3",
"Select States:",
choices = unique(mobese1_df$state)),
uiOutput("bcheckbox"),
plotOutput("barPlot")
)
服务器:
output$bcheckbox <- renderUI({
choice <- unique(mobese1_df[mobese1_df$state %in% input$select3])
checkboxGroupInput("mcheckbox", " ", choices = choice)
})
output$barPlot<- renderPlot({
bplot_data <- mobese1_df %>% filter(state %in% input$select3)
ggplot(bplot_data, aes(x = state, y = mean_gain)) + geom_bar(stat="identity") +
ggtitle("Male Mean Obesity Increase by State 2001 - 2009") +
xlab("State") + ylab("Percent Increase")
我正在使用多复选框过滤器来允许选择特定状态。当我尝试发布到 shinyapps 时,我收到错误:警告:[.data.frame 中的错误:选择了未定义的列
为什么会这样?我已经尝试过以我能想到的各种方式修改代码。
解决方案
确保您使用的所有包都已加载
library(shiny)
library(tidyverse)
ui <- fluidPage(
checkboxGroupInput("select3",
"Select States:",
choices = unique(mobese1_df$state)),
uiOutput("bcheckbox"),
plotOutput("barPlot")
)
server <- function(input, output, session){
output$bcheckbox <- renderUI({
choice <- unique(mobese1_df[mobese1_df$state %in% input$select3])
checkboxGroupInput("mcheckbox", " ", choices = choice)
})
output$barPlot<- renderPlot({
bplot_data <- mobese1_df %>% filter(state %in% input$select3)
ggplot(bplot_data, aes(x = state, y = mean_gain)) + geom_bar(stat="identity") +
ggtitle("Male Mean Obesity Increase by State 2001 - 2009") +
xlab("State") + ylab("Percent Increase")})
}
shinyApp(ui, server)
这对我来说很好,没有错误,你可以在这里看到
推荐阅读
- bash - docker 图像输出操作
- ruby-on-rails - 如何使用 POST 请求通过 link_to 传递参数?
- java - 如何在数组中显示分段信息?
- python - mysql 查询过滤器 LIKE 无法正常工作
- linux - 使用 Shell 脚本在 URL 中查找 (/) 的第一次出现
- java - AWS StartSpeechSynthesisTaskRequest
- postgresql-11 - 错误:[050]:无法获取文件“/tmp/pgbackrest/demo-archive.lock”的锁定:权限被拒绝
- javascript - 如何将折线添加到传单地图中
- php - Symfony - 处理大量插入的数据
- php - 提交表单后在codeigniter中上传多个文件