2
我已經拖了大約一天的互聯網試圖解決這個問題。我有一個閃亮的應用程序,用戶可以切換數據庫,輸出顯示在googleVis地理位置上。在沒有使用開關的情況下,圖表完美呈現,但是一旦在UI中使用開關,圖表就會消失。我用一個actionButton和一個eventReactive語句暫時解決了這個問題,但這意味着用戶必須點擊按鈕才能刷新(不是最優)。我擔心這是GoogleVis的問題還是我的代碼中的錯誤。我可以告訴你,dygraph與開關完美結合,使我相信它是googleVis。 這裏是我的UI閃亮的googleVis GeoChart不顯示與反應開關
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("State Data Table",
tabName = "state",
icon = icon("dashboard")),
menuItem("State Complaint Map",
tabName = "MAP",
icon = icon("bar-chart-o")),
menuItem("Daily Data Table",
tabName = "Day",
icon = icon("dashboard")),
menuItem("Daily Time Series Plot",
tabName = "TZ",
icon = icon("bar-chart-o")),
selectInput("data",
"Data View",
choices=c("Product","Sub Product"),
multiple=FALSE),
uiOutput("input1"),
fluidRow(column(width=1),
actionButton("generate","Generate State Plot"))
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "state",
h2("State Data Table"),
DT::dataTableOutput("state")
),
tabItem(tabName ="Day",
h2("Daily Data table"),
DT::dataTableOutput("day")),
tabItem(tabName="MAP",
h2("State Map"),
htmlOutput("StatePlot")),
tabItem(tabName="TZ",
h2("Time Series Plot"),
fluidRow(
column(width=4),
column(width=4,
box(width=NULL,
uiOutput("input2")))),
box(width=12,
dygraphOutput("DYEGRAPH1")))
)
)
ui <- dashboardPage(
dashboardHeader(title = "CFPB Complaints"),
sidebar,
body
)
這裏是我的server.R
server <- function(input, output) {
ProductView.st <- reactive({
switch(input$data,
"Product"=cfpb.st,
"Sub Product"=cfpb.st.sp)
})
ProductView.ts <- reactive({
switch(input$data,
"Product"=cfpb.ts,
"Sub Product"=cfpb.ts.sp)
})
output$input1 <- renderUI({
if(is.null(input$data))
return(NULL)
Var <- ProductView.st()
selectInput("product",
"Select Product for State Map",
choices=levels(Var$Product),
multiple=FALSE)
})
output$input2 <- renderUI({
if(is.null(input$data))
return(NULL)
Var <- ProductView.ts()
selectInput("product2",
"Select Product",
choices=levels(Var$Product),
multiple=FALSE)
})
output$day <- DT::renderDataTable({
datatable(ProductView.ts(),extensions = 'TableTools',
rownames=FALSE,class = 'cell-border stripe',filter="top",
options = list(
searching=TRUE,
autoWidth=TRUE,
paging=TRUE,
"sDom" = 'T<"clear">lfrtip',
"oTableTools" = list(
"sSwfPath" = "//cdnjs.cloudflare.com/ajax/libs/datatables-
tabletools/2.1.5/swf/copy_csv_xls.swf",
"aButtons" = list(
"copy",
"print",
list("sExtends" = "collection",
"sButtonText" = "Save",
"aButtons" = c("csv","xls"))))))
})
output$state <- DT::renderDataTable({
datatable(ProductView.st(),extensions = 'TableTools',
rownames=FALSE,class = 'cell-border stripe',filter="top",
options = list(
searching=TRUE,
autoWidth=TRUE,
paging=FALSE,
"sDom" = 'T<"clear">lfrtip',
"oTableTools" = list(
"sSwfPath" = "//cdnjs.cloudflare.com/ajax/libs/datatables-
tabletools/2.1.5/swf/copy_csv_xls.swf",
"aButtons" = list(
"copy",
"print",
list("sExtends" = "collection",
"sButtonText" = "Save",
"aButtons" = c("csv","xls"))))))
})
plot1 <- eventReactive(input$generate,{
state <- ProductView.st()
state <- subset(state,Product == input$product)
state
})
output$StatePlot <- renderGvis({
gvisGeoChart(plot1(),"State","Complaints To Population *
10000",options=list(region="US",
displayMode="regions",
resolution="provinces",
height=650,width=1100))
})
dygraph1 <- reactive({
if(is.null(input$data))
return(NULL)
t <- ProductView.ts()
t$Date.received <- as.Date(t$Date.received,format="%Y-%m-%d")
t <- t[t$Product == input$product2,]
t <- t[,-2]
t <- as.xts(t,order.by=t$Date.received)
t
})
output$DYEGRAPH1 <- renderDygraph({
dygraph(dygraph1(),main="Complaints since 2012") %>%
dyAxis("y",label = "Number of Complaints") %>%
dyRangeSelector()
})
}
shinyApp(ui, server)
我想我想通了。檢查此帖:http://stackoverflow.com/questions/34579494/googlevis-does-not-work-properly-with-two-dependent-widget-shiny –