如何绘制mySql服务器中存储的表

如何绘制mySql服务器中存储的表,mysql,shiny,Mysql,Shiny,我正在尝试绘制一个存储在MySQL服务器中的表,其中包含可在变量之间进行选择的选项。但当我试图绘制它时,我得到了一个错误: eval(expr、envir、enclose)中出错:找不到对象“x” 我是R新手,因此无法解决问题 我的代码是: library(shiny) library(ggvis) ui<-fluidPage( div(), titlePanel("Hello User"), sidebarLayout( sideb

我正在尝试绘制一个存储在MySQL服务器中的表,其中包含可在变量之间进行选择的选项。但当我试图绘制它时,我得到了一个错误:

eval(expr、envir、enclose)中出错:找不到对象“x”

我是R新手,因此无法解决问题

我的代码是:

library(shiny)
library(ggvis)

ui<-fluidPage( 

 div(),       
  titlePanel("Hello User"),       
sidebarLayout(      
  sidebarPanel(   

    selectInput('x', 'x:' ,'x'),    
    selectInput('y', 'y:', 'y'),      
    uiOutput("plot_ui")      
  ),    

  mainPanel(      
  ggvisOutput("plot")     
    )
    )
    )

server<-function(input, output, session) {      
library(RMySQL)    
options(mysql = list(   

  "host" = "sub**********",        
  "port" = 3306,          
  "user" = "bss",       
  "password" = "m******"       
))       

databaseName <- "niitmathlogic"         
table <- "ILS_Analysis"                  
saveData <- function(data) {       

  # 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 update query by looping over the data fields       

  query <- sprintf(      

    "INSERT INTO %s (%s) VALUES ('%s')",     
    table,             
    paste(names(data), collapse = ", "),       
    paste(data, collapse = "', '")           
  )             

  # Submit the update query       

  dbGetQuery(db, query)

}

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 case when city_dd = 'Bangalore' then 'Bangalore'    

when city_dd = 'New Delhi' then 'New Delhi'      

when city_dd = 'Chennai' then 'Chennai'        

when city_dd = 'Mumbai' then 'Mumbai'        

when city_dd = 'Kolkata' then 'Kolkata'        

else 'Others' end as type, count(*) as leads, sum(conversion_flag) as conversion          
from %s where duration_2flag =1 group by type", table)       

# Submit the fetch query         

  data <- dbGetQuery(db, query)      

  data            

}                

observe({        

    data<-loadData()          

    updateSelectInput(session, 'x', choices = names(data))           

    updateSelectInput(session, 'y', choices = names(data))          

  }) # end observe

  #gets the y variable name, will be used to change the plot legends

  yVarName<-reactive({

    input$y

  })

 #gets the x variable name, will be used to change the plot legends

  xVarName<-reactive({

    input$x

  })

filteredData<-reactive({          

    data<-isolate(loadData())       


    #if there is no input, make a dummy dataframe          

    if(input$x=="x" && input$y=="y"){                

      if(is.null(data)){               

        data<-data.frame(x=0,y=0)              

      }               
    }else{             

      data<-data[,c(input$x,input$y)]      

      names(data)<-c("x","y")           
    }              

    data         

  })           


 vis<-reactive({          

    plotData<-filteredData()               

    plotData %>%                

    ggvis(~x, ~y) %>%           

    layer_points() %>%          

    add_axis("y", title = yVarName()) %>%          

    add_axis("x", title = xVarName()) %>%              

    add_tooltip(function(df) format(sqrt(df$x),digits=2))           

  })                  

    vis%>%bind_shiny("plot", "plot_ui")          

}      

shinyApp(ui,server)
库(闪亮)
图书馆(ggvis)

请格式化代码!我已经格式化了代码,我认为问题在于vis函数。请帮我解决这个问题。由于
vis
是一种反应式,我想您需要在最后一行中使用
vis()