2016-03-04 25 views
0
**UI.R** 

library(shiny) 

shinyUI 
    (fluidPage 
    (
     titlePanel("Predict"), 

     sidebarLayout 
     (
     sidebarPanel 
      (
      (numericInput("tenth", label = h3("X Percentage"), value = 90))), 
     mainPanel("Main Panel") 
    ) 
    ) 
) 


**Server.R** 

library(shiny) 
library(RMySQL) 


shinyServer(
    function(input,output) 
    { 
    db <- dbConnect(MySQL(), dbname = "rstudio", host = "localhost", 
        port = 3306, user = "root", password = "") 

    query <- sprintf("SELECT * FROM userdetails where SSC = %s",input$tenth) 
    } 
) 

误差不允许 操作而不活性反应性上下文。 (您试图做一些只能从反应式表达式或观察者内部完成的事情。)查询在闪亮ř使用反应性输入到从数据库中检索数据

我知道我需要在反应性表达式或隔离中添加数据库查询。但我怎么写。我需要将检索到的数据显示给用户,甚至将数据用于进一步的计算。

回答

0

也许使get_data()反应server.R里面的function(input, output)东西。

get_data <- reactive({ 
    query <- sprintf("SELECT * FROM userdetails where SSC = %s",input$tenth) 
    df <- dbSendQuery(conn, query) 
    return(df) 
}) 

再后来就用get_data()访问这些数据...