1

我对 Rshiny 很陌生。我写了这段代码:

ui=source('./www/uixx2.R')

server = function(input,output){}

shinyApp(ui = ui, server = server)

The uixx2.R file is placed in the subdirectory www and the code is:

ui=shinyUI("Why am i getting:  ")

输出是: 为什么我得到:FALSE

每次使用源函数时,我的输出底部都会出现 FALSE。

4

2 回答 2

3

您分配给 ui 变量两次。该行ui = source('./www/uixx2.R')正在创建错误,因为 ui 成为源代码和 FALSE 的列表,然后闪亮显示。在变量查看器中检查它。

通常 source("file.R") 不应用于分配给变量,因为它没有定义的返回值。(或者至少在通常情况下?帮助它什么也没说)

这个有效。

source('./www/uixx2.R')    
server = function(input,output){}    
shinyApp(ui = ui, server = server)

The uixx2.R file is placed in the subdirectory www and the code is:    
ui=shinyUI("Why am i getting:  ")
于 2020-11-25T06:42:34.833 回答
1

我强烈推荐以下内容:在 RStudio 中,转到文件 -> 新文件 -> Shiny Web App

这样,它会自动为你建立一个结构,让你很难出错

但是要回答这个问题,你ui可以是一个函数,就像这样

ui <- source('./www/uixx2.R')[[1]] # This takes the first list item (i.e. the function - see below)

server = function(input,output){}

shinyApp(ui = ui, server = server)

# In uixx2.R, simply put:

function() {
  shinyUI("Why am i getting: ")
  # Anything else goes here ...
}

在此处输入图像描述

于 2020-11-25T06:51:48.263 回答