2017-06-03 7 views
0

Ich bin von ggplot für meine glänzende app plotly, aber wenn ich app von Rstudio laufen die plots nicht im Browser angezeigt, wenn ich print (gg) die plotly korrekt in Rstudio Viewer zeigt. Das folgende minimale Beispiel funktioniert, wenn ich zu ggplot zurückwechsle. Vielen Dank!glänzend plotly keine Grafik

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

Sollte funktionieren, aber ohne die Datei '" CRANlog_cleaned_month.RData "' gibt es keine echte Möglichkeit zu sagen, was falsch ist. Sieht gut aus. Machen Sie ein MWE (minimales Arbeitsbeispiel) und wir können Ihnen vielleicht helfen. –

Antwort

0

ich dies aus "Plot1" durch die Änderung des Namens von selectInput zu lösen gelang auf einen anderen Namen, möglicherweise wegen der plotlyOutput ist auch mit "plot1". Das war in Ordnung, wenn ich nur plotOutput benutze. Wahrscheinlich fehlt in plotlyOutput ein Fehlercode.

Verwandte Themen