图中不显示闪亮
我有一个Shiny应用程序,显示硅谷公司员工的种族和员工数量之间的关系。左侧的工具栏是可见的,但情节未显示。我应该如何更改我的代码?图中不显示闪亮
下面是代码:
library(shiny) library(ggplot2)
library(dplyr)
bcl <- read.csv("E:/country/data/reveal.csv")
ui <- fluidPage(
titlePanel("Silicon valley"),
sidebarLayout(
sidebarPanel(
sliderInput("countInput", "count", 0, 100, c(25, 40)),
radioButtons("jobInput", "Job category",
choices = c("Technicians", "Professionals", "Sales workers", "Administrative support"),
selected = "Technicians"),
selectInput("companyInput", "company",
choices = c("Twitter", "Uber", "View"))
),
mainPanel(
plotOutput("coolplot"),
br(), br(),
tableOutput("results")
)
)
)
server <- function(input, output) {
output$coolplot <- renderPlot({
filtered <-
bcl %>%
filter(count == input$countInput,
job_category == input$jobInput,
company == input$companyInput
)
ggplot(filtered, aes(race)) +
geom_histogram()
})
}
shinyApp(ui = ui, server = server)
这里是结果:
回答:
试试这个:
library(shiny) library(ggplot2)
library(dplyr)
bcl <- read.csv(file = "reveal.csv", colClasses = c("character", "integer", "factor", "factor", "factor", "integer"), na.strings = c("na", "NA")) %>% na.omit()
ui <- fluidPage(titlePanel("Silicon valley"),
sidebarLayout(
sidebarPanel(
sliderInput("countInput", "count", 0, 100, c(0, 100)),
radioButtons(
"jobInput",
"Job category",
choices = c(
"Technicians",
"Professionals",
"Sales workers",
"Administrative support"
),
selected = "Technicians"
),
selectInput("companyInput", "company",
choices = c("Twitter", "Uber", "View"))
),
mainPanel(plotOutput("coolplot"),
br(), br(),
tableOutput("results"))
))
server <- function(input, output) {
output$coolplot <- renderPlot({
filtered <-
bcl %>%
filter(
count == input$countInput,
job_category == input$jobInput,
company == input$companyInput
)
ggplot(filtered, aes(race)) +
geom_bar()
})
}
shinyApp(ui = ui, server = server)
我已经改变geom_histogram
到geom_bar
,因为它是为您的数据提供更好的选择。让我知道你的想法。
以上是 图中不显示闪亮 的全部内容, 来源链接: utcz.com/qa/266701.html