如何正确创建r代码的exe

时间:2017-01-04 09:10:07

标签: r vbscript shiny exe

我想让我的用户使用<asp:RegularExpressionValidator ID="FileValidationPDF" runat="server" ControlToValidate="OFile" ErrorMessage="Only PDF Allowed" ValidationExpression="([a-zA-Z0-9\s_\\.\-:])+(.pdf)$"></asp:RegularExpressionValidator> 使用library(shiny);runGist("xxx")存储的闪亮应用。 为此,我创建了一个包含便携式Chrome,便携式R和2个文件的文件夹:

1 - run.R - 包含以下代码:

library(shiny);runGist("xxx")

2 - 应调用run.r的VBScript,以便调用runGist。

Randomize
CreateObject("Wscript.Shell").Run "R-Portable\App\R-Portable\bin\R.exe CMD BATCH --vanilla --slave run.R" & " " & RND & " ", 0, False

当我点击VBScript时没有任何反应所以我想我错过了什么,怎么能解决这个问题呢?

更新:点击run.vbs后我得到了一个编号文件,当我在Notepad ++上打开它时,我得到了以下文字:

Downloading https://gist.github.com/#############/download
NULL
[1] TRUE

Listening on http://127.0.0.1:1337

当我将http://127.0.0.1:1337复制到浏览器时,它会提供我想要的内容。 那么问题是如何使用消息中提供的地址调用浏览器? - 我注意到每次点击都会给出另一个地址。

3 个答案:

答案 0 :(得分:5)

您可以覆盖默认浏览器选项,然后使用runGist launch.browser即可。

<强> run.R

#Assuming your portable Chrome's relative path is "Chrome\Application\chrome.exe"
options(browser = normalizePath("Chrome\\Application\\chrome.exe"));

library(shiny);
runGist("xxx", launch.browser = TRUE);

<强> run.vbs

Set Fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("Wscript.Shell")
    'specify CD to start commands from script's parent folder
    WshShell.CurrentDirectory = Fso.GetParentFolderName(WScript.ScriptFullName)

'Start the command as hidden and don't wait
WshShell.Run "R-Portable\App\R-Portable\bin\R.exe CMD BATCH --vanilla --slave run.R NUL", 0, False

答案 1 :(得分:2)

从VBScript的角度来看,正如您所使用的只是相对路径,如果当前的活动目录(计算相对路径的位置)不是您认为可能存在问题的那些。

您可以尝试使用(详细版本)

之类的内容
/** 
 * @test
 */
public function throw_exception_when_application_status_is_modified_after_submission()
{
    /**
     * Arrange
     */
    // create roles
    factory(Role::class, 'admin')->create();
    factory(Role::class, 'applicant')->create();

    // create admin user
    $adminUser = factory(User::class)->create();
    $adminUser->attachRole(Role::whereName('admin')->first());
    // create applicant user
    $applicantUser = factory(User::class)->create();
    $applicantUser->attachRole(Role::whereName('applicant')->first());

    // create organisation with type
    $organisationType = factory(OrganisationType::class)->create();
    $organisation = factory(Organisation::class)->create();
    $organisation->organisationTypes()->attach($organisation->id);

    // create sub application
    $subApplication = factory(ExperienceLetter::class)->create();

    // create applicant
    $applicant = factory(Applicant::class)->create([
        'user_id' => $applicantUser->id
    ]);

    // create application
    $application = factory(Application::class)->make([
        'status' => 'pending',
        'application_id' => $subApplication->id,
        'application_type' => 'App\Models\ExperienceLetter',
        'organisation_id' => $organisation->id,
        'applicant_id' => $applicant->id,
    ]);    

    // prep data
    $data = [
        'action' => 'accept',
        'details' => 'email sent',
        'application_id' => $application->id,
        'application_status' => 'pending',
        'verification' => 'email',
    ];

    /**
     * Act
     */
    // log in
    $this->actingAs($adminUser);

    // alter status before call()
    $application->status = 'verification';
    $application->save();

    $response = $this->call('POST', route('admin.application.action.store'), $data);

    /**
     * Assert
     */
    $this->assertEquals(302, $response->status());
    // assertSessionHasErrors
}

答案 2 :(得分:2)

关于您的更新: 注意,您可以在runApp()中将端口号设置为参数 例如:runApp(...,port = 1337)

示例:

n <- 200


# Define the UI
ui <- bootstrapPage(
  numericInput('n', 'Number of obs', n),
  plotOutput('plot')
)


# Define the server code
server <- function(input, output) {
  output$plot <- renderPlot({
    hist(runif(input$n))
  })
}

# Return a Shiny app object
runApp(shinyApp(ui = ui, server = server), port = 1337)

编辑:回答后续行动:

如果这没有帮助:

library(shiny);runGist(..., launch.browser = TRUE, port = 1337)

试试这个:

library(shiny);runGist(..., port = 1337);browseURL("http://127.0.0.1:1337")