Plotly can't show on shiny (I have downloaded the patched file. But the problem is the same as usual.)

library(shiny)
library(plotly)
library(dplyr)
library(scales)
library(reticulate)
source_python("cems_api.py")

ui <- fluidPage(
  plotlyOutput("plot")
)

server <- function(input, output) {
  
  # renderPlotly() also understands ggplot2 objects!
  output$plot <- renderPlotly({
    SO_table$polno <- as.factor(unlist(SO_table$polno))
    SO_table$m_time <- as.POSIXct(SO_table$m_time, format="%Y/%m/%d %H:%M")
    SO_ggplot<- SO_table %>% ggplot(aes(x = m_time, y = m_val, color=polno)) + 
      geom_point() +
      geom_line()+
      theme_bw()+
      labs(y="ppm")+
      scale_x_datetime(date_labels="%m/%d %H:%M:%S")
    SO_linechart <- ggplotly(SO_ggplot)
  })
  
}

shinyApp(ui, server)

Hello, everyone. There is a big problem in the code which I can't handle. It shows that "Warning: Error in isReallyReal: x must be of type double." But I have set and checked class and typeof are the same as the dataset in the example. Moreover, it works independently (not on shiny). So, I don't know how to solve it. Can someone teach me?

Here are my code and file needed.
https://drive.google.com/open?id=12JPV9AaLfoCBb_VsFJOiDowdQHwOu_Qy

Hi @Karen, can you also provide the "cems_api.py" script so we can reproduce your example?

Hello, @cpsievert . Sorry for that I can't provide cems_api.py for you because the file connects to database. But there is a file called SO_table.csv thar contains all data needed for the plotly and the column names are the same as typed in the previous code.

I added that the lines "SO_table <- instant_24("E5600056") %>% subset(item == '922') NO_table <- instant_24("E5600056") %>% subset(item == '923')" can be replaced with SO_table <- read_table("SO_table.csv", header = TRUE, sep = ","). So, the instant_24 will not influence the program.

This generates a sensible looking plot for me:

library(shiny)
library(plotly)


ui <- fluidPage(
    plotlyOutput("plot")
)

server <- function(input, output) {
    
    # renderPlotly() also understands ggplot2 objects!
    output$plot <- renderPlotly({
        SO_table <- read.table("~/Downloads/my file (1)/SO_table.csv", header = TRUE, sep = ",")
        
        SO_table$polno <- as.factor(unlist(SO_table$polno))
        SO_table$m_time <- as.POSIXct(SO_table$m_time, format="%Y/%m/%d %H:%M")
        SO_ggplot<- SO_table %>% ggplot(aes(x = m_time, y = m_val, color=polno)) + 
            geom_point() +
            geom_line()+
            theme_bw()+
            labs(y="ppm")+
            scale_x_datetime(date_labels="%m/%d %H:%M:%S")
        SO_linechart <- ggplotly(SO_ggplot)
    })
    
}

shinyApp(ui, server)

The error you originally reported likely has something to do with using python/reticulate to pull from your database

Thank you for your reply. I will try it by myself. :grin:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.