我正在尝试将包含以下数据的条形图发布到闪亮的应用程序上:
for i in range(0, 100, 7):
print(i)
if i == 0:
continue
if i % 11 == 0:
break
我用于发布到Shinyapps中的代码是:
UI:
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
服务器:
ui <- fluidPage(
checkboxGroupInput("select3",
"Select States:",
choices = unique(mobese1_df$state)),
uiOutput("bcheckbox"),
plotOutput("barPlot")
)
我正在使用一个多复选框过滤器,以允许选择特定状态。当我尝试发布到Shinyapps时,出现错误:警告:[.data.frame:错误未选定列中的错误
为什么会这样?我试图以我能想到的所有方式修改代码。
答案 0 :(得分:0)
确保已加载您使用的所有软件包
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)
这对我来说很好,没有错误,如您所见here