radioButtons()输入,作为筛选数据帧的一个条件,不使用';好像不行
使用radioButtons()输入,作为筛选数据帧的一个条件,不使用';好像不行,r,ggplot2,dplyr,shiny,R,Ggplot2,Dplyr,Shiny,使用ggplot2中的midwest数据帧: #(在app_ui.r中) 贫困侧边栏因此提供的代码很接近,您犯了两个错误 选项不需要映射到数字 x=country,y=poppovertyknown应该在geom\u col的aes中,所以aes(x=country,y=poppovertyknown) 因此,最终的工作代码将是(注意,我已将赋值添加到ui,以使其在单个文件中工作,并调用shinyApp(ui,server)) 库(闪亮) 图书馆(dplyr) 图书馆(GG2) 贫困侧边栏使用c
ggplot2
中的midwest
数据帧:
#(在app_ui.r中)
贫困侧边栏因此提供的代码很接近,您犯了两个错误
选项
不需要映射到数字
x=country,y=poppovertyknown
应该在geom\u col的aes
中,所以aes(x=country,y=poppovertyknown)
因此,最终的工作代码将是(注意,我已将赋值添加到ui
,以使其在单个文件中工作,并调用shinyApp(ui,server)
)
库(闪亮)
图书馆(dplyr)
图书馆(GG2)
贫困侧边栏使用choices=list(“IL”、“IN”、“MI”、“OH”、“WI”)
会给我同样的错误:“Objectcountry
not found”这些小错误会毁掉一切。非常感谢!
library(shiny)
library(dplyr)
library(ggplot2)
poverty_sidebar <- sidebarPanel(
radioButtons(
inputId = "state",
label = "State",
choices = list("IL", "IN", "MI", "OH", "WI"), # remove mapping to integers
selected = "IL"
))
poverty_plot <- mainPanel(
plotOutput(
outputId = "poverty_plot"
)
)
ui <-
fluidPage(
poverty_sidebar,
poverty_plot
)
# (in app_server.r)
server <- function(input, output) {
output$poverty_plot <- renderPlot({
filtered <- filter(midwest, state == input$state)
print(filtered)
print(input$state)
filtered0 <<- filtered
plot <-
filtered %>%
ggplot() +
geom_col(aes(x = county, y = poppovertyknown)) # used aes()
return(plot)
})
}
shinyApp(ui, server)