My question is: how to use ggplotly properly on Shiny ?
我的问题是:如何在Shiny上正确使用ggplotly?
The code works fine without the "ggplotly()" line at the end. I dont know why Shiny didn't make the graphics...
代码工作正常,最后没有“ggplotly()”行。我不知道为什么Shiny没有制作图形......
And the page is forcing me to write "some more details", because "it looks like your post is mostly code" and I dont know what more to say...
该页面迫使我写“更多细节”,因为“它看起来像你的帖子主要是代码”,我不知道还有什么要说的......
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)
1 个解决方案
#1
2
I got it !
我知道了 !
In the UI
在UI中
plotlyOutput("variacion", height = "80%")
and in the server
并在服务器中
output$variacion <- renderPlotly({
#1
2
I got it !
我知道了 !
In the UI
在UI中
plotlyOutput("variacion", height = "80%")
and in the server
并在服务器中
output$variacion <- renderPlotly({