2017-01-19 91 views
0

我的問題是:如何在Shiny上正確使用ggplotly?如何在Shiny上正確使用ggplotly

代碼工作正常,沒有在最後的「ggplotly()」行。我不知道爲什麼閃亮沒有使圖形...

而該網頁迫使我寫「一些更多的細節」,因爲「它看起來像你的文章主要是代碼」,我不知道更多的說...

library(shiny) 
library(leaflet) 
library(ggplot2) 


ui <- fluidPage(
    leafletOutput("mymap"), 
    p(), 
    vars <- c(
    "Las Cruzadas" = "cruzadas" 
), 

    absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE, 
    draggable = TRUE, top = "auto", left = "auto", right = "auto", bottom = 60, 
    width = 900, height = "auto", 

    h2("Serie nivel napa"), 

    selectInput("color", "Estacion", vars), 

    plotOutput("variacion", height = 100) 



) 
) 
server <- function(input, output, session) { 

    output$mymap <- renderLeaflet({ 
    leaflet() %>% 
     addTiles() %>% 
     addCircleMarkers(lng=-71.294444, lat=-32.933333, color="blue" ,popup="ESTACION: 'LAS CRUZADAS'") 
    }) 
    output$variacion <- renderPlot({ 
    setwd("C:/Documents and Settings/waldo.solar.g/Escritorio") 
    datos=read.csv("cruzadas.csv", sep=";", header = TRUE) 
    names(datos) <- c("fecha","hora","altura") 
    datos$fecha <- gsub("[[:punct:]]","/",datos$fecha) 
    datos$hora <- gsub(":00",":00:00",datos$hora) 
    datos$altura[ datos$altura == "---" ] = NA 
    datos$altura2 <-as.numeric(as.character(datos[,3])) * -1 
    datos$horafecha <- strptime(paste(datos$fecha, datos$hora), format = "%d/%m/%Y %H:%M:%S") 
    theme_set(theme_bw()) 
    ggplot(aes(x = datos$horafecha, y = datos$altura2), data = datos) + 
     geom_line() + 
     geom_point() + 
     #geom_point(aes(y = datos$altura2, color = "Linear"), size = 3, alpha = 0.5) + 
     stat_smooth(colour='blue', span=0.2) + 
     ylab("Altura (m) ") + 
     xlab("Meses") 

    ggplotly() #THIS LINE CONTAINS THE ERROR. HELP! :) 
    }) 
} 

shinyApp(ui, server) 

回答

2

我明白了!

在UI

plotlyOutput("variacion", height = "80%") 

,並在服務器

output$variacion <- renderPlotly({