[問題] 如何使用shiny textInput()

看板R_Language作者 (asdfrtg)時間6年前 (2018/12/11 21:05), 6年前編輯推噓1(104)
留言5則, 3人參與, 7年前最新討論串1/1
[問題類型]: 程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來) [軟體熟悉度]: 使用者(已經有用R 做過不少作品) [問題敘述]: 想嘗試將ui端輸入的文字帶入函式中,按下執行鈕後出現錯誤 Warning: Error in [: incorrect number of dimensions 想請問出現此錯誤是因為server 與ui沒有對應到,或是帶入函式方法錯誤 [程式範例]: shinyServer( function(input, output,session) { library(rsconnect) library(tseries) library(quantmod) library(forecast) library(car) library(haven) observeEvent( input$goButton,{ index2<-as.character( input$index1) getSymbols(c(index2),from = "1900-01-05") index.open<-data.frame(as.numeric(c(index2)[,1])) index.open.year<-data.frame(tail(index.open,365)) colnames(index1.open.year)="OP.value" output$year.plot<-renderPlot(plot(index.open.year,main = "index plot")) output$value<-renderTable(data.frame(tail(index.open.year,5))) })}) library(shiny) library(rsconnect) shinyUI(fluidPage( titlePanel("index plot and table"), mainPanel( textInput( "index1",label = "index") , actionButton("goButton", "Go!"), plotOutput("year.plot"), tableOutput("value") ))) [環境敘述]: R 3.5 shiny [關鍵字]: shiny ui 輸入 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.96.98.58 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1544533545.A.FC3.html

12/12 08:07, 6年前 , 1F
你input$index1的輸入有幾個?
12/12 08:07, 1F

12/12 08:37, 6年前 , 2F
textInput的話就算你輸入["YHOO","QQQ"]還是會當成一個字串
12/12 08:37, 2F

12/12 08:37, 6年前 , 3F
不知道是不是這個問題@@
12/12 08:37, 3F

12/12 12:43, 6年前 , 4F
問題出在c(index2)[,1],你的index又不是dataframe
12/12 12:43, 4F
感謝! 因為第一次試按鈕以及文字輸入 後來使用 index3<-getSymbols(c(index2),from = "1900-01-05",auto.assign = FALSE) index.open<-data.frame(index3[,1])) 就成功了! ※ 編輯: asdfrtg (175.96.98.58), 12/14/2018 00:28:03

01/23 22:58, 7年前 , 5F
推推大神HumuHumu
01/23 22:58, 5F
文章代碼(AID): #1S3xOf_3 (R_Language)
文章代碼(AID): #1S3xOf_3 (R_Language)