0

I'm trying to plot my data from the sensor i choose in the SelectInput, so far i have no errors but also no plot.

So when someone visits the page, he can select a sensor en the data of that sensor will be plotted on the Y-axis and the timestamp on the X-axis.

I already asked the question but i'm still stuck at the same point. Did alot of research online but I can't seem to find the answer.

Here is my code

Server.R

library(shiny)
library(RMySQL)
options(mysql = list(
  "host" = "185.56.135.42",
  "port" = 3306,
  "user" = "xxx",
  "password" = "xxx"
))
databaseName <- "pxleai1q_1305141"
table <- "sensorParser"





shinyServer(function(input, output) {
  loadData <- eventReactive(input$doQuery, {
    # Connect to the database
    db <- dbConnect(MySQL(), dbname = databaseName, host = options()$mysql$host, 
                    port = options()$mysql$port, user = options()$mysql$user, 
                    password = options()$mysql$password)
    # Construct the fetching query
    query <- sprintf("SELECT Value FROM %s where sensor = '%s'", table, input$sensor)

    # Submit the fetch query and disconnect
    data <- dbGetQuery(db, query)
    dbDisconnect(db)
    data;

  })

  # output$plot <- renderPlot({plot(fsrData$timestamp ~ fsrData$value, fsrData = loadData())})
  output$plot <- renderPlot({plot(timestamp ~ value, data = loadData())})
 output$text1 <- renderText({
   paste("dump: ", input$sensor)

 })

})

ui.R

library(shiny)
library(RMySQL)

shinyUI(fluidPage(

  # Application title
  titlePanel("Visualisatie gegevens"),

  # Sidebar with a slider input for number of bins
  sidebarLayout(
    sidebarPanel("hier ziet u de visualisatie van de gegevens",
                 selectInput("sensor", 
                  label = "choose a variable to display",
                   choices = list("FSR", "HumSensor", "TempSensor","BPMSensor")),
                 actionButton("doQuery", label = "weergave")
                 ),


    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("Plot"),
      textOutput("text1")

    )
  )
))

this is de database I'm trying to read

id id_wasp id_secret frame_type frame_number sensor value timestamp raw parser_type
1926 Waspmote 403476432 128 19 TIME 0­5­22 2016­03­16 12:06:51 noraw 0
1927 Waspmote 403476432 128 19 FSR 273 2016­03­16 12:06:51 noraw 0
1928 Waspmote 403476432 128 19 HumSensor 130 2016­03­16 12:06:51 noraw 0
1929 Waspmote 403476432 128 19 TempSensor0 0 2016­03­16 12:06:51 noraw 0
1930 Waspmote 403476432 128 19 BPMSensor 0 2016­03­16 12:06:51 noraw 0
1931 Waspmote 403476432 128 20 TIME 0­5­29 2016­03­16 12:06:58 noraw 0
1932 Waspmote 403476432 128 20 FSR 1023 2016­03­16 12:06:58 noraw 0
1933 Waspmote 403476432 128 20 HumSensor 897 2016­03­16 12:06:58 noraw 0
1934 Waspmote 403476432 128 20 TempSensor627 627 2016­03­16 12:06:58 noraw 0
1935 Waspmote 403476432 128 20 BPMSensor 280 2016­03­16 12:06:58 noraw 0
1936 Waspmote 403476432 128 21 TIME 0­5­35 2016­03­16 12:07:05 noraw 0
Maarten
  • 1
  • 2
  • Is the problem on the database's side or R code? Can you make it work reading from a fixed file, like a csv, txt or perhaps a sqlite database? – Roman Luštrik Mar 21 '16 at 13:19
  • You select only `Value`, but try to plot `timestamp ~ value` may be problem here? ( try select 2 column) + colnames after dbGetquery may be in upper case , try print `colnames (loadData())` before plot – Batanichek Mar 21 '16 at 13:37

0 Answers0