Hello people. sorry for my English.
I use ReactivePoll on server.R to feed my chart data every 15 seconds.
The graph I use is a Plotly scatter plot, but it must have an image in the background that is the floor plan of a set of rooms. Each point on the scatterplot is a sensor in each room.
Every 15 seconds the points on the graph update their data, but the background image also renders.
How do I not render the background image? I want it fixed.
Thank you!!
example of my code in server.R
fetch data from the database:
shop_instantaneo <- reactivePoll(15000, session,
checkFunc = function() {
con <- con()
max_date <- dbGetQuery(con, "SELECT MAX(timestampdado) AS max_date
FROM rtm")
max_date$max_date <- as.POSIXct(max_date$max_date)
dbDisconnect(con)
return(max_date)
},
valueFunc = function() {
con <- con()
# construct the SQL statement
sql <- "select idrtm, idequip, temperatura, timestampdado
from shop.rtm"
shop_instantaneo <- dbGetQuery(con, sql)
shop_instantaneo$timestampdado <- as.POSIXct(shop_instantaneo$timestampdado)
dbDisconnect(con)
return(shop_instantaneo)
}
)
graph plotly
output$plot_map_1andar<-renderPlotly({
andar <- input$tabs
width <- session$clientData$output_plot_map_1andar_width
height <- session$clientData$output_plot_map_1andar_height
npixels <- width * height
config_layout <- config_layout()
config_layout <- config_layout %>% filter(config_layout$cod_panel == andar)
mintemp <- config_layout$range_min
maxtemp <- config_layout$range_max
equipamentos <- equipamentos()
image_file <- "SMO_L1.png"
txt <- RCurl::base64Encode(readBin(image_file, "raw", file.info(image_file)[1, "size"]), "txt")
instantaneo = shop_instantaneo()
resultado <- merge(x = instantaneo,
y = equipamentos) %>% filter(equipamentos$idandar == '1')
p <- plot_ly(x = resultado$xposition, y = resultado$yposition,
type = 'scatter',
hoverinfo = 'text',
text = ~paste("Nome do Sensor:",resultado$nome,
"<br>Temperatura: ", (resultado$temperatura)/100,
"ºC<br>Localização: ", resultado$referencia),
color = (resultado$temperatura)/100,
colors = colorRamp(c(config_layout$color_min,config_layout$color_med, config_layout$color_max)),
mode = "markers",
marker = list(size = (20*npixels)/1055200)) %>%
colorbar (title= "Temperatura:\n <br>", limits = c(mintemp,maxtemp)) %>%
layout(
images = list(
list(
source = paste('data:image/png;base64', txt, sep=','),
layer ="below",
xref = 'x',
yref = 'y',
x = 0,
y = 1,
sizex = 1,
sizey = 1,
sizing = "stretch",
opacity = 0.9
)),
xaxis = list(range = c(0, 1), showgrid = FALSE, visible = FALSE),
yaxis = list(range = c(0, 1), showgrid = FALSE, visible = FALSE),
height = width/3)
p
})
excerpt from ui.r
tabPanel('1º Andar',
icon = icon("list-ol"),
value='#2andar',
br(),
plotlyOutput("plot_map_1andar"))