我一直在嘗試開發一種有選擇性輸入的交互式Boxplot Shiny。使用Shiny製作boxplot交互式
當前代碼:
library(shiny)
shinyUI(fluidPage(
titlePanel("Sample 1"),
sidebarLayout(
sidebarPanel(
selectInput("p", "Choose your salaries", choices = c("low"='a',"mid"='b',"high"='c',"riches!"='d'), selected = 4)
),
mainPanel(
plotOutput("boxplot")
)
)
))
library(shiny)
read.csv("Salaries.csv")
Categories <- cut (Salaries$TotalPay, breaks = c(0,36466,73678,104359,567595), labels = c("low","mid","high","riches!"))
shinyServer(function(input, output){
output$boxplot <- renderPlot({
if(input$p=='a'){
i<"1"
}
if(input$p=='b'){
i<-"2"
}
if(input$p=='c'){
i<-"3"
}
if(input$p=='d'){
i<- "riches!"
}
boxplot(TotalPay~Categories[i])
})
})
我不能讓箱線圖來在UI中所做的選擇反應。我懷疑它與水平做,因爲當我打電話:
> Categories["riches!"]
[1] <NA>
Levels: low mid high riches!
' 我是否需要因素都增加了這些?或者我完全錯過了這一點? 在此先感謝!
您是否將您的csv文件分配給數據框?在我看來,你失蹤了: 薪水< - read.csv(「Salaries.csv」) –