2017-01-19 8 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({