每次运行代码时,filter_impl都会出错:结果的长度必须为101766,而不是0。这发生在两个地方,我也不知道为什么。
UI代码
ui <- dashboardPage(
dashboardHeader(title = "Diabetes in the United States"),
dashboardSidebar(
sidebarMenu(
menuItem(tabName = "diabetes", "Diabetes")
)
),
dashboardBody(
fluidRow(
box(width = 4, solidHeader = TRUE, status = "primary",
selectInput("Race", "Choose patient race: ", choices = " "),
radioButtons("genderInput", "Choose Gender: ",
list("Female", "Male", "Unknown/Invalid")
)
),
infoBoxOutput("progressBox"),
box( width = 8, height = '700px', solidHeader = TRUE, status = "primary",
mainPanel(
plotlyOutput("coolplot", width = '900px', height = '600px')
# tableOutput("results")
)
)
)
)
)
服务器代码
server <- function(input, output, session) {
patientRace = sort(unique(diabetes$race))
updateSelectInput(session, "Race", choices = patientRace)
gender = sort(unique(diabetes$gender))
output$coolplot <- renderPlotly({
diabetes <-
diabetes %>%
filter(race == input$race,
gender == input$gender
)
p = ggplot(diabetes, aes(x = race, fill = gender)) +
geom_bar(position = "stack")
ggplotly(p) %>%
layout(showlegend = FALSE)
})
output$progressBox <- renderInfoBox({
infoBox(
input$race,
value = paste("Total", nrow(diabetes %>% filter(race == input$race)),
collapse = " "),
icon = icon("user-friends"),
color = "purple",
fill = T
)
})
}
我希望图表和信息框根据用户为种族和性别选择的内容进行更新。