[問題] shiny呼叫local端R檔

看板R_Language作者 (jumbo100830)時間6年前 (2018/01/15 00:15), 編輯推噓1(1020)
留言21則, 2人參與, 6年前最新討論串1/1
[問題類型]: 程式諮詢 [軟體熟悉度]: Shiny新手 [問題敘述]: 問題1 : 我試寫了一個網站,在server.R的地方呼叫了另一個R(a.R),但之前一直在local端跑都沒發現問題,後來放上shinyapp.io才發現問題。 不知道如果我如果要把網頁放上網,我的a.R要怎麼呼叫才行,之前我都使用source(a.R),那我的server.R放上網要怎麼呼叫local端的a.R檔? 問題2 : 我ui.R的要輸出表格,也想要輸出圖片,而圖片和表格都在a.R檔計算好了,可是server.R在寫的時候就要指定輸出的形式是什麼,如:output$x <- renderTable(...)。 我的a.R中有表格(table1)、圖(pic1)、字串(string1 ) 我嘗試過使用 output$x <- renderTable(a.R) #表格#table1 output$y <- renderPlot(a.R) #圖#pic1 output$z <- renderText(a.R) #字串#string1 結果失敗,他只會輸出表格,我想是因為我的a.R最下面一個變數是表格(pic1)的關係。 ui.R同時想輸出a.R裡面的多樣東西的時候怎麼使用呢? 因為剛接觸用法很多都不熟悉,還請各位指點。 如果大家有什麼推薦的shiny教學,也希望可以推薦給我。 非常謝謝大家。 ----- Sent from JPTT on my iPhone -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.247.164.249 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1515946547.A.6D4.html

01/15 01:16, 6年前 , 1F
source(file, local=TRUE) file也可以指定在相對子目錄下
01/15 01:16, 1F

01/15 01:19, 6年前 , 2F
x <- reactiveValues(dt=data.frame(), str="")之後在a.R
01/15 01:19, 2F

01/15 01:20, 6年前 , 3F
x$dt=YourTable;x$str=YourStr..用法像list but reactive
01/15 01:20, 3F

01/15 01:22, 6年前 , 4F
renderTable(x$dt)..教學看Rstudio官網有gallery code..
01/15 01:22, 4F

01/15 21:39, 6年前 , 5F
x <- reactiveValues(dt = data.frame(),str ="")
01/15 21:39, 5F

01/15 21:39, 6年前 , 6F
x$dt = YourTable;x$str=YourStr等是都放在server.R中
01/15 21:39, 6F

01/15 21:39, 6年前 , 7F
嗎? 下面這樣對嗎?(server.r)
01/15 21:39, 7F

01/15 21:39, 6年前 , 8F

01/15 21:39, 6年前 , 9F
然後指定變數是放在a.R嗎?
01/15 21:39, 9F

01/15 21:39, 6年前 , 10F

01/15 21:39, 6年前 , 11F
因為都沒有噴錯也沒出現東西?想請問我是不是有弄錯
01/15 21:39, 11F

01/15 21:39, 6年前 , 12F
如果我想將ui.R的變數放到a.R中,a.R處理完再把圖拿出
01/15 21:39, 12F

01/15 21:39, 6年前 , 13F
來放到server.R和ui.R中使用該怎麼辦?
01/15 21:39, 13F

01/15 22:34, 6年前 , 14F
shiny reactivity應在observe() or observeEvent完成
01/15 22:34, 14F

01/15 22:35, 6年前 , 15F
或者利用reactive(), eventReactive()回傳reactive變數值
01/15 22:35, 15F

01/15 22:36, 6年前 , 16F
也可以,建議若不清楚可參考一下網路上眾多範例便會明白
01/15 22:36, 16F

01/15 22:39, 6年前 , 17F
比如observe({x$val<-YourFunc(input$control); ....})
01/15 22:39, 17F

01/15 22:42, 6年前 , 18F
ui.R server.R是可以有global變數,但通常ui.R就是給
01/15 22:42, 18F

01/15 22:43, 6年前 , 19F
client端的control,和server端聯繫就用input$ or session
01/15 22:43, 19F

01/15 22:45, 6年前 , 20F
如果你的a.R try_fun是像圖中這樣呼叫,不會有reactivity
01/15 22:45, 20F

01/15 22:48, 6年前 , 21F
所以你的資料若一次性就算完,根本也不用reactive變數..
01/15 22:48, 21F
文章代碼(AID): #1QMu8pRK (R_Language)