我正在创建一个闪亮的应用程序,但是table5不能正常工作,R表示 Error in :: NA/NaN argument
。有人对现在发生的事情有任何想法吗?对于Tabale 5,我正在使用表1和表2中的数据...
另一个问题是闪亮的应用程序内部,有很多数据需要清理,我应该将数据清理到闪亮的应用程序外部吗?还是应该只将数据保留在应用程序内部?哪个效率更高?
非常感谢!
library(shiny)
library(plotly)
library(dplyr)
library(readxl)
library(tidyr)
Index_2 <- read_xlsx('Index 2.xlsx')
Index_11 <- read_xlsx('Index 11.xlsx')
whole_country_list <- read_xlsx('whole country list.xlsx')
country_list <- sort(unique(whole_country_list$`Country Name`))
Index_2 <- filter(Index_2, Country %in% whole_country_list$`whole list`) %>%
left_join(whole_country_list, by = c("Country" = "whole list" )) %>%
select(- Country) %>%
select(`Country Name`, everything())
Index_11 <- filter(Index_11, Country %in% whole_country_list$`whole list`) %>%
left_join(whole_country_list, by = c("Country" = "whole list" )) %>%
select(- Country) %>%
select(`Country Name`, everything())
ui <- shinyUI(fluidPage(
titlePanel("Input panel"),
sidebarLayout(
sidebarPanel(
selectInput("country_in",
"Choose one country:",
choices = country_list,
selected = 'Benin')
),
mainPanel(
tabsetPanel(
tabPanel("VAR 2:Meta data on school system, computed from INDEX 2", dataTableOutput("table1")),
tabPanel("VAR 3: Population data, computed from INDEX 11", dataTableOutput("table2")),
tabPanel("VAR 4: School-age population data, computed from VAR 2 AND 3", dataTableOutput("table5"))
)
)
)
)
)
server <- shinyServer(function(input, output) {
dataInput1 <- reactive({
out <- dplyr::filter(Index_2, `Country Name` == input$country_in)
out})
dataInput2 <- reactive({
out <- filter(Index_11, `Country Name` == input$country_in & `INDEX 11: Popuiation indicators` %in%
c("Age population, age 03, female, interpolated",
"Age population, age 03, male, interpolated",
"Age population, age 04, female, interpolated",
"Age population, age 04, male, interpolated",
"Age population, age 05, female, interpolated",
"Age population, age 05, male, interpolated",
"Age population, age 06, female, interpolated",
"Age population, age 06, male, interpolated",
"Age population, age 07, female, interpolated",
"Age population, age 07, male, interpolated",
"Age population, age 08, female, interpolated",
"Age population, age 08, male, interpolated",
"Age population, age 09, female, interpolated",
"Age population, age 09, male, interpolated",
"Age population, age 10, female, interpolated",
"Age population, age 10, male, interpolated",
"Age population, age 11, female, interpolated",
"Age population, age 11, male, interpolated",
"Age population, age 12, female, interpolated",
"Age population, age 12, male, interpolated",
"Age population, age 13, female, interpolated",
"Age population, age 13, male, interpolated",
"Age population, age 14, female, interpolated",
"Age population, age 14, male, interpolated",
"Age population, age 15, female, interpolated",
"Age population, age 15, male, interpolated",
"Age population, age 16, female, interpolated",
"Age population, age 16, male, interpolated",
"Age population, age 17, female, interpolated",
"Age population, age 17, male, interpolated",
"Age population, age 18, female, interpolated",
"Age population, age 18, male, interpolated",
"Age population, age 19, female, interpolated",
"Age population, age 19, male, interpolated",
"Age population, age 20, female, interpolated",
"Age population, age 20, male, interpolated",
"Age population, age 21, female, interpolated",
"Age population, age 21, male, interpolated",
"Age population, age 22, female, interpolated",
"Age population, age 22, male, interpolated",
"Age population, age 23, female, interpolated",
"Age population, age 23, male, interpolated",
"Age population, age 24, female, interpolated",
"Age population, age 24, male, interpolated"
)) %>%
separate(col = `INDEX 11: Popuiation indicators`, into = c("X1", "X2", "X3", "Age", "Sex", "X6", "X7"), sep = ' ')%>%
mutate(
Age = as.numeric(gsub(",","", Age)),
Sex = gsub(",","", Sex)) %>%
select(`Country Name`, Sex, Age, `2008`:`2050`) %>%
arrange(desc(Sex), Age)
out})
dataInput5 <- reactive({
out <- as.data.frame(mapply(function(x,y) {
c(y[x[1]-2], # first acceptable age
sum(y[(x[1]-2):(x[1]-2+x[2])]), # sum within range
y[x[1]-2+x[2]]) # last acceptable age
},
dataInput1()[-c(1:2)],dataInput2()[-c(1:3)])
)
out})
output$table1 <- renderDataTable({
dataInput1()
})
output$table2 <- renderDataTable({
dataInput2()
})
output$table5 <- renderDataTable({
dataInput5()
})
})
shinyApp(ui, server)