File upload 图像上传在闪亮

File upload 图像上传在闪亮,file-upload,shiny,File Upload,Shiny,我一直在试图找出如何通过一个闪亮的应用程序从本地计算机上传图像,但我很难确定如何访问图像,以便在服务器端代码中使用它,然后将其保存到远程位置。现在,我已经使用jQuery(如下所示)尝试了fileInput()和自定义HTML代码。 这是应用程序的服务器和用户界面代码 shinyServer(function(input, output) { output$your_species <- renderText({ current_species }) output$curre

我一直在试图找出如何通过一个闪亮的应用程序从本地计算机上传图像,但我很难确定如何访问图像,以便在服务器端代码中使用它,然后将其保存到远程位置。现在,我已经使用jQuery(如下所示)尝试了
fileInput()
和自定义HTML代码。

这是应用程序的服务器和用户界面代码

shinyServer(function(input, output) {

output$your_species <- renderText({
    current_species
})

output$current_sp <- renderText({
    current_species
})

# output$your_image <- renderImage({
#   input$image_upload
# }, deleteFile = FALSE)

source("pages/main_page.R")
source("pages/help_page.R")

header <- dashboardHeader(title="End. Sp. Images")

sidebar <- dashboardSidebar(disable=TRUE)

body <- dashboardBody(
    main_page,
    help_page
)
dashboardPage(header, sidebar, body, skin="blue")

main_page <- {
fluidPage(
    column(1,
        img(src="01_DOW_LOGO_COLOR_100.png"),
        tags$hr()#,
    ),
    column(11,
        tabsetPanel(
            tabPanel(title="Main",
                tags$h3(textOutput("your_species"), style=make_bold()),
                fluidRow(
                    column(4,
                        box(title="Image information",
                            collapsible=TRUE,
                            status="primary",
                            solidHeader=TRUE,
                            height=NULL,
                            width=NULL,
                            textInput("species",
                                label="Species",
                                value=current_species
                            ),
                            textInput("img_src",
                                label="Image source",
                                value="http://"
                            ),
                            selectInput("license",
                                label="Image license",
                                choices=list_of_licenses,
                                selected="Select..."
                            ),
                            textInput("attribution",
                                label="Image attribution",
                                value="To whom should attribution be given?"
                            ),
                            tags$hr(),
                            tags$p("Drop photo on button or click to choose", 
                                   style="color:gray"
                            ),
                            # fileInput("image_upload",
                            #     label="Photo upload"
                            # ),
                                    tags$div(  
                              HTML(html_txt)
                                    ),
                            submitButton("Submit")

                            # htmlOutput("wikimedia_embed")
                        )
                    ),
                    column(5,
                        box(title="Your image",
                            collapsible=TRUE,
                            status="primary",
                            solidHeader=TRUE,
                            height=500,
                            width=NULL,
                            imageOutput("your_image",
                                height=NULL,
                                width="100%"
                            )
                        )
                    ),
                    column(3,
                        tags$p("Some search options", style=make_18_bold()),
                        tags$p("Pre-formatted searches", style="color:gray"),
                        infoBox(
                            title="First option",
                            value=tags$a("Wikimedia", 
                                         href=wiki_srch,
                                         target='_blank'),
                            icon=icon("picture-o"),
                            color="light-blue",
                            width=NULL
                        ),
                        # infoBox(
                        #     title="Second option",
                        #     value=tags$a("CC Search", 
                        #                  # href="http://search.creativecommons.org",
                        #                  href=cc_search,
                        #                  target='_blank'),
                        #     icon=icon("picture-o"),
                        #     color="light-blue",
                        #     width=NULL
                        # ),
                        infoBox(
                            title="Second option",
                            value=tags$a("Google Image Search", 
                                         href=goog_srch,
                                         target='_blank'),
                            icon=icon("picture-o"),
                            color="light-blue",
                            width=NULL
                        ), #,
                        tags$p("Creative Common portal", style="color:gray"),
                        infoBox(
                            title="Check here too!",
                            value=tags$a("CC Search", 
                                         href="http://search.creativecommons.org",
                                         target='_blank'),
                            icon=icon("picture-o"),
                            color="light-blue",
                            width=NULL
                        )
                    )
                )
            )
        )
    )
)
}
shinyServer(功能(输入、输出){

输出$your_species我添加了闪亮的代码来帮助解释我正在尝试做什么。我添加闪亮的代码来帮助解释我正在尝试做什么。
// A list of permitted file extensions
$allowed = array('png', 'jpg', 'gif','zip');

if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){

$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);

if(!in_array(strtolower($extension), $allowed)){
    echo '{"status":"error"}';
    exit;
}

if(move_uploaded_file($_FILES['upl']['tmp_name'], 'uploads/'.$_FILES['upl']['name'])){
    echo '{"status":"success"}';
    exit;
}
}

echo '{"status":"error"}';
exit;
shinyServer(function(input, output) {

output$your_species <- renderText({
    current_species
})

output$current_sp <- renderText({
    current_species
})

# output$your_image <- renderImage({
#   input$image_upload
# }, deleteFile = FALSE)

source("pages/main_page.R")
source("pages/help_page.R")

header <- dashboardHeader(title="End. Sp. Images")

sidebar <- dashboardSidebar(disable=TRUE)

body <- dashboardBody(
    main_page,
    help_page
)
dashboardPage(header, sidebar, body, skin="blue")

main_page <- {
fluidPage(
    column(1,
        img(src="01_DOW_LOGO_COLOR_100.png"),
        tags$hr()#,
    ),
    column(11,
        tabsetPanel(
            tabPanel(title="Main",
                tags$h3(textOutput("your_species"), style=make_bold()),
                fluidRow(
                    column(4,
                        box(title="Image information",
                            collapsible=TRUE,
                            status="primary",
                            solidHeader=TRUE,
                            height=NULL,
                            width=NULL,
                            textInput("species",
                                label="Species",
                                value=current_species
                            ),
                            textInput("img_src",
                                label="Image source",
                                value="http://"
                            ),
                            selectInput("license",
                                label="Image license",
                                choices=list_of_licenses,
                                selected="Select..."
                            ),
                            textInput("attribution",
                                label="Image attribution",
                                value="To whom should attribution be given?"
                            ),
                            tags$hr(),
                            tags$p("Drop photo on button or click to choose", 
                                   style="color:gray"
                            ),
                            # fileInput("image_upload",
                            #     label="Photo upload"
                            # ),
                                    tags$div(  
                              HTML(html_txt)
                                    ),
                            submitButton("Submit")

                            # htmlOutput("wikimedia_embed")
                        )
                    ),
                    column(5,
                        box(title="Your image",
                            collapsible=TRUE,
                            status="primary",
                            solidHeader=TRUE,
                            height=500,
                            width=NULL,
                            imageOutput("your_image",
                                height=NULL,
                                width="100%"
                            )
                        )
                    ),
                    column(3,
                        tags$p("Some search options", style=make_18_bold()),
                        tags$p("Pre-formatted searches", style="color:gray"),
                        infoBox(
                            title="First option",
                            value=tags$a("Wikimedia", 
                                         href=wiki_srch,
                                         target='_blank'),
                            icon=icon("picture-o"),
                            color="light-blue",
                            width=NULL
                        ),
                        # infoBox(
                        #     title="Second option",
                        #     value=tags$a("CC Search", 
                        #                  # href="http://search.creativecommons.org",
                        #                  href=cc_search,
                        #                  target='_blank'),
                        #     icon=icon("picture-o"),
                        #     color="light-blue",
                        #     width=NULL
                        # ),
                        infoBox(
                            title="Second option",
                            value=tags$a("Google Image Search", 
                                         href=goog_srch,
                                         target='_blank'),
                            icon=icon("picture-o"),
                            color="light-blue",
                            width=NULL
                        ), #,
                        tags$p("Creative Common portal", style="color:gray"),
                        infoBox(
                            title="Check here too!",
                            value=tags$a("CC Search", 
                                         href="http://search.creativecommons.org",
                                         target='_blank'),
                            icon=icon("picture-o"),
                            color="light-blue",
                            width=NULL
                        )
                    )
                )
            )
        )
    )
)
}