2017-06-03 73 views
0

我從ggplot切換到我的閃亮應用程序,但是當我從Rstudio運行應用程序時,如果我在Rstudio查看器中正確顯示打印(gg),則無法在瀏覽器中顯示情節。如果我切換回ggplot,下面的最小示例工作。謝謝!閃亮的情節沒有圖

ui.R

library(shiny) 
library(httr) 
library(jsonlite) 

# get the list of all packages on CRAN 
package_names = names(httr::content(httr::GET("http://crandb.r- 
pkg.org/-/desc"))) 

shinyUI(fluidPage(

# Application title 
"R Package Downloads", 

# Sidebar with a slider input for number of bins 
sidebarLayout(
sidebarPanel(
    br(), 
    selectInput("package", 
       label = "Packages", 
       selected = "ggplot2", # initialize the graph with a random package 
       choices = package_names, 
       multiple = TRUE),  
    selectInput("plot1", 
       label = "Select Plot Type", 
       choices = c("","Downloads vs Time (monthly)","Downloads vs Time (cumulative)","Map (cumulative)","Map (dominance)"), 
       multiple = FALSE)), 

# Show a plot of the generated distribution 
mainPanel(
    plotlyOutput("plot1") 
)) 
)) 

server.R

library(shiny,quietly = T); library(stringr,quietly = T) 
library(dplyr,quietly = T); library(plotly,quietly = T) 
library(ggplot2,quietly = T); library(lubridate,quietly = T) 
library(cranlogs,quietly = T); library(zoo,quietly = T) 
library(scales,quietly = T); library(broom,quietly = T) 
library(rworldmap,quietly = T); library(countrycode,quietly = T) 
library(data.table,quietly = T) 

shinyServer(function(input, output) { 
    load("CRANlog_cleaned_month.RData") 
    output$plot1 <- renderPlotly({ 
    dat.p <<- subset(dat,package %in% input$package) 
    dat.ts <<- aggregate(times~package+month,data=dat.p,sum) 
     DTmonthly <<- ggplot(dat.ts, aes(month, times, color = package)) + 
     geom_line() + xlab("Date") + scale_y_continuous(name="Number of downloads", labels = comma) 
     gg <- ggplotly(DTmonthly) 
     gg 
    }) 
}) 
+0

應該工作,但沒有文件「CRANlog_cleaned_month.RData」,沒有真正的方法來說明什麼是錯的。看起來很好。做一個MWE(最小工作示例),我們可能會提供幫助。 –

回答

0

我設法從 「plot1」 改變selectInput的名稱到另一個名稱來解決這個問題,可能是因爲plotlyOutput是也使用「plot1」。這很好,如果我只是使用plotOutput。可能由於plotlyOutput中缺少一些錯誤檢查代碼。