0
我在Windows 10 64bit上使用R 3.2.3到RStudio版本0.99.491 ...我创建了一个ggplot2闪亮的应用程序,它显示气泡图。我不明白,我得到除了事实上,它是有关输入错误消息:如何在shiny/ggplot2应用上的一个selectInput中使用多个data.frame对象
Warning in validateSelected(selected, choices, inputId) :
'selected' must be the values instead of names of 'choices' for the input 'month'
Warning: Error in ..stacktraceon..: object 'input' not found
Stack trace (innermost first):
1: shiny::runApp
Error in ..stacktraceon..({ : object 'input' not found
这里是我使用的data。下面是代码
UI
library(shiny)
library(leaflet)
vars = c("april" = "April","may" = "May","june" = "June","july" = "July")
shinyUI(pageWithSidebar(
sidebarPanel(
selectInput("month", "Month", vars, selected = "april")),
mainPanel(plotOutput("plot")
)))
SEVER
library(shiny)
library(leaflet)
melt_april <- melt(april)
names(april) = c('departure', 'stop', 'frequency')
melt_may <- melt(may)
names(may) = c('departure', 'stop', 'frequency')
melt_june <- melt(june)
names(june) = c('departure', 'stop', 'frequency')
melt_july <- melt(july)
names(july) = c('departure', 'stop', 'frequency')
monthBy <- input$month
shinyServer(function(input, output){
observe({
output$plot <- renderPlot({
p <- ggplot(monthBy, aes(x = departure, y =stop, size = frequency, color = frequency)) +
geom_point()+
scale_colour_gradient(low="white",high="orange")+
print(p)
)
})
})
非常感谢!该应用程序没有崩溃!这是进步。它给了我一个错误,而不是剧情:'ggplot2不知道如何处理类字符的数据'但它是否意味着像data.frame这样的类? –
是的!输入$ month返回一个字符串。我认为你想要那个字符串的名称的数据框?你可以这样做一些尴尬的事情:'eval(as.name(monthBy))'来获取实际的数据框架,但我认为可能有更好的方法。 –
闪亮是棘手的调试。确保你理解了你想要放入应用程序的所有代码,并且在开始投入Shiny之前,它都会运行。 –