当我尝试引入动态selectInput字段时,闪亮R中的gvisBubbleChart绘图停止显示
我在开发一个应用程序时遇到了这个问题,并在这里使用Fruits df以简化脚本复制了它。 基本上,我有选择输入框来选择一年,这是水果中的一列。我创建了唯一的年份列表,并将其输入到selectInput框中。 然后,理想情况下,我希望我的绘图只显示我选择的年份的记录。但是,正如您在我的代码中所看到的,当您取消注释一个由3行组成的块以完成此操作时,即使看起来没有任何错误,绘图也会停止显示。有人知道这是为什么吗?提前感谢 相关问题-在调试时,我看到输入$explore\u year最初是“Null”。我试图在代码中处理这个问题,但不确定为什么selected=“2010”不能自动处理它当我尝试引入动态selectInput字段时,闪亮R中的gvisBubbleChart绘图停止显示,r,shiny,googlevis,R,Shiny,Googlevis,我在开发一个应用程序时遇到了这个问题,并在这里使用Fruits df以简化脚本复制了它。 基本上,我有选择输入框来选择一年,这是水果中的一列。我创建了唯一的年份列表,并将其输入到selectInput框中。 然后,理想情况下,我希望我的绘图只显示我选择的年份的记录。但是,正如您在我的代码中所看到的,当您取消注释一个由3行组成的块以完成此操作时,即使看起来没有任何错误,绘图也会停止显示。有人知道这是为什么吗?提前感谢 相关问题-在调试时,我看到输入$explore\u year最初是“Null”。
library(shiny)
library(googleVis)
library(DT)
listOfFruits <- sort(unique(Fruits$Year), decreasing = FALSE)
ui <- fluidPage(title = "Fruits Bug Recreated",
fluidRow(
column(3,
wellPanel(
uiOutput("choose_year"),
br()
)),
column(9,
tags$hr(),
htmlOutput("view")
)),
fluidRow(DT::dataTableOutput("tableExplore"))
)
server <- function(input, output) {
output$view <- renderGvis({
#Uncomment these 3 lines to see how the plot stops displaying.
# local_exloreYear <- input$explore_year
# if (is.null(local_exloreYear)) {local_exloreYear <- "2010"}
# FruitsSubset <- subset(Fruits, Year == local_exloreYear)
#------------I wanted to use the commented line below instead of the
#that follows
#gvisBubbleChart(FruitsSubset, idvar="Fruit",
#-------------
gvisBubbleChart(Fruits, idvar="Fruit",
xvar="Sales", yvar="Expenses",
colorvar="Year", sizevar="Profit",
options=list(
hAxis='{minValue:70, maxValue:125, title:"Sales"}',sortBubblesBySize=TRUE,
vAxis='{title: "Expenses",minValue:60, maxValue:95}'
))
})
# Drop-down selection box for dynamic choice of minutes in the plans to compare
output$choose_year <- renderUI({
selectInput("explore_year", "Select Year", as.list(listOfFruits),selected ="2010")
})
output$tableExplore <- DT::renderDataTable(DT::datatable({
FruitsSubset <- subset(Fruits, Fruits$Year == input$explore_year)
myTable <-FruitsSubset[,c(1,2,3,4,5,6)]
data <- myTable
data
},options = list(searching = FALSE,paging = FALSE)
))
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(谷歌)
图书馆(DT)
listofruits就像我在评论中写的那样,您可以通过将呈现条件设置为输入为非空来解决它
output$view <- renderGvis({
if(!is.null(input$explore_year)){
...
}
})
output$view您可以通过确保input$explore\u year
不为空来解决此问题:output$view谢谢!您的修复程序适用于这种特殊情况,但不幸的是,我的应用程序有点复杂,需要为两个不同的变量呈现不同的绘图,因此-我需要在renderGvis中添加一些条件,然后这个错误就阻碍了我的工作(我认为你认为这是一个错误是正确的。我转而使用plotly作为气泡图来避免这个问题。再次感谢!sry听到。好吧,我会报告它,同时你可以对所有需要的变量进行“空测试”作为解决方法。或者你也可以像Mike Wise在另一篇帖子中建议的那样,。。