2016-08-16 9 views
1

私は最近Rシャイニーを学び始めました。光り輝くアプリを作ろうとしましたが失敗しました。私の問題は:私は自分のコンピュータ上でローカルcsvファイルを使用し、学生の名前の型のようなカスタム関数を使用して単純なルックアップを実行し、彼/彼女の学生IDを返そうとします。以下は私のコードです:Rシャイニー - ローカルcsvファイルとカスタム機能の使い方

ui.R 

library(shiny) 

shinyUI(fluidPage(

    # application title 
    titlePanel("FGMC Search Engine"), 

    sidebarLayout(
    sidebarPanel(
    textInput("text",label = h3("Correspondent Search"), value = "Enter Here...") 
), 

mainPanel(
    textOutput("text1") 
) 
) 

)) 

、その後

server.R 
library(shiny) 

# define function for inputing the corr array & input and return channel source 
corr_search <- function(corr,input_name){ 
    # lowercase of input names 
    name_lower = tolower(input_name) 
    # lowercase of corr names 
    corr_lowercase = substr(tolower(corr$TPO.Company.Name),1,nchar(test_lowercase)) 
    # look up the corresponding channel source accounding to matched corr indexing 
    result = corr$Channel.Source[match(test_lowercase, corr_lowercase)] 
    # check if search result is Null 
    if (is.na(result)){ 
    result = "Wrong Input! Please Search Again" 
    } 
    # return search result 
    return(result) 
} 



shinyServer(
    function(input, output) { 

    textInput <- reactive({ 
    corr = read.csv("C:\\Users\\carl.qin\\Desktop\\Projects\\Modelling & Analytics\\R Modelling\\App-2\\fgmc_correspondent.csv",header=TRUE) 
    input_name = input$text 
    If(is.na(input_name)){ 
    input_name = "nothing" 
    } 
}) 

result = corr_search(corr,input_name) 

output$text1 <- renderPrint({ 

    result 
}) 

} 
) 

私はエラーを取得しておく:オブジェクトが見つかりません。もし誰かがこの問題を解決することができれば幸いです。

ありがとうございました!

答えて

0

関数corr_searchでは、変数test_lowercaseは使用されていません(存在しないためエラーです)。 reactiveにはifを使用していますが、誤植があります。 (Ifの代わりにifが必要です)。また、あなたに感謝textInput()

+1

を経由して(あなたがinput_nameを定義した)反応性表現textInputresult = corr_search(corr, input_name)を移動すると、あなたが最終的にrenderPrintに渡す値を返す必要があります。私はRが新しく輝いているので、気づかなかったいくつかの間違いを作った。 私はあなたの指示に従ってコードを変更しました。今、私はそれに多くの機能を追加することができます。 –

関連する問題