【发布时间】:2020-07-02 12:22:53
【问题描述】:
我有以下闪亮的应用程序: 数据集:(https://www.kaggle.com/rush4ratio/video-game-sales-with-ratings)
library(shinythemes)
library(shiny)
library(ggplot2)
ui = navbarPage(theme = shinytheme("united"),"Video Games Dashboard",
tabPanel("Dashboard",
sidebarLayout(
sidebarPanel(
selectInput(inputId = "dataset",
label = "Choose a dataset:",
choices = colnames(data)),
),
mainPanel(
plotOutput(outputId = "ggPlot"),
plotOutput(outputId = "ggPlot2"),
)
)
),
tabPanel("Summary",
)
)
server <- function(input, output) {
output$ggPlot <- renderPlot({
ggplot ( data=data,aes(x=Global_Sales, y=input$dataset)) +
geom_bar(stat="identity" ,fill="steelblue") +
coord_flip() +
theme_minimal()
})
output$ggPlot2 <- renderPlot({
ggplot ( data=data,aes(x=Global_Sales, y=Platform)) +
geom_bar(stat="identity" ,fill="steelblue") +
theme_minimal()
})
}
shinyApp(ui = ui, server = server)
正如你所看到的,我想在第一个 plot("ggPlot") 中做同样的事情,就像在第二个 plot("ggPlot2") 中一样,只是第一个 plot 是响应式的,您可以选择要显示的数据表的每一列它在情节中。 但是,我一直收到这条消息:
asJSON(keep_vec_names=TRUE) 的输入是一个命名向量。在 jsonlite 的未来版本中,将不支持此选项,命名向量将被转换为数组而不是对象。如果您想要 JSON 对象输出,请改用命名列表。请参阅 ?toJSON。
有人知道如何解决这个问题吗?这种方法甚至可能吗?
谢谢!
【问题讨论】:
-
你确定第一个情节是你所期望的,只有一个酒吧?如果要将
y设置为名称为input$dataset的变量,可以使用aes_string(x="Global_Sales", y=input$dataset)。在您的代码中,y未设置为数据变量,因为input$dataset是一个字符串。 -
嗨,Stéphane,当我写 aes_string 时,你很难过它有效!谢谢!为什么 input$dataset 是一个字符串?