我有关于selectizeInput的问题。如果我有更多选定的输入,我如何获得他们的值。存在一些像输入$选择[1],输入$选择[2]? 谢谢。
我的代码:
data<-data.frame(c("Mexico","China","Italy","Italy","Mexico"),c(120,130,125,140,145),c("Book","Table","Desk","Window","Rabbit"))
colnames(data)<-c("State","Count","Name")
selectizeInput("mySelect",label="choose",multiple=TRUE,choices=colnames(data),
options =list(maxItems=2,plugins = list('remove_button', 'drag_drop')))
我需要这个渲染
ggplot(data,aes(input$mySelect[1],input$mySelect[2]))
答案 0 :(得分:2)
您需要使用aes_string
并为您的情节添加geom
。但是你在寻找这样的东西:
data<-data.frame(c("Mexico","China","Italy","Italy","Mexico"),c(120,130,125,140,145),c("Book","Table","Desk","Window","Rabbit"))
colnames(data)<-c("State","Count","Name")
ui <- fluidPage(
selectizeInput("mySelect",label="choose",multiple=TRUE,choices=colnames(data),
options =list(maxItems=2,plugins = list('remove_button', 'drag_drop'))),
plotOutput('my_plot')
)
server <- function(input,output,session) {
output$my_plot <- renderPlot({
ggplot(data,aes_string(input$mySelect[1],input$mySelect[2])) + geom_point()
})
}
shinyApp(ui,server)