我一直在尝试在 Shiny 中开发具有选择性输入的交互式箱线图。
当前代码:
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!
' 我需要添加这些因素吗?还是我完全没有抓住重点?提前致谢!
看看如何按名称访问列。下面的例子是mtcars
数据集
library(shiny)
ui <- fluidPage(
selectInput("p","p",choices = names(mtcars)),
plotOutput("myplot"))
server <- function(input, output, session) {
output$myplot <- renderPlot({
boxplot(mtcars[,input$p])
})
}
shinyApp(ui, server)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句