I'm new to shiny but I think I know how I can get my information from my dataset with the code from the website.
I'm working on a project where i store my sensor data in a Phpmyadmin database, now i just need to extract this information and show it in a reactive graph.
loadData <- function() {
# 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", table)
# Submit the fetch query and disconnect
data <- dbGetQuery(db, query)
dbDisconnect(db)
data // HOW DO I LOAD THIS DATASET
}
but how do i call this data for plotting?
SO i changed to code
ui.R
library(shiny)
library(RMySQL)
shinyUI(fluidPage(
# Application title
titlePanel("Visualisatie gegevens"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(),
# Show a plot of the generated distribution
mainPanel(
plotOutput("plot")
)
)
))
because i just need a graph in my layout and a title
server.R
library(shiny)
library(RMySQL)
options(mysql = list(
"host" = "185.68.145.42",
"port" = 3306,
"user" = "user",
"password" = "******"
))
databaseName <- "user"
table <- "sensorParser"
shinyServer(function(input, output) {
output$plot <- renderPlot({plot(x~y, data = loadData)})
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", table)
# Submit the fetch query and disconnect
data <- dbGetQuery(db, query)
dbDisconnect(db)
data
})
})
this is de data in the database i'm using
id id_wasp id_secret frame_type frame_number sensor value timestamp raw parser_type
1 Waspmote 403476432 128 65 FSR 48 20160308 12:26:46 noraw 0
2 Waspmote 403476432 128 66 FSR 48 20160308 12:26:51 noraw 0
3 Waspmote 403476432 128 67 FSR 49 20160308 12:26:56 noraw 0
4 Waspmote 403476432 128 68 FSR 49 20160308 12:27:00 noraw 0
5 Waspmote 403476432 128 69 FSR 49 20160308 12:27:05 noraw 0
6 Waspmote 403476432 128 70 FSR 49 20160308 12:27:09 noraw 0
7 Waspmote 403476432 128 71 FSR 49 20160308 12:27:14 noraw 0
8 Waspmote 403476432 128 72 FSR 49 20160308 12:27:19 noraw 0
9 Waspmote 403476432 128 73 FSR 49 20160308 12:27:23 noraw 0
10 Waspmote 403476432 128 74 FSR 48 20160308 12:27:28 noraw 0
11 Waspmote 403476432 128 75 FSR 48 20160308 12:27:32 noraw 0
12 Waspmote 403476432 128 76 FSR 47 20160308 12:27:37 noraw 0
13 Waspmote 403476432 128 77 FSR 48 20160308 12:27:42 noraw 0
14 Waspmote 403476432 128 78 FSR 49 20160308 12:27:46 noraw 0
15 Waspmote 403476432 128 0 FSR 38 20160308 12:27:52 noraw 0