我无法使用shinny在R studio上打印图像

时间:2015-12-09 05:16:52

标签: shiny rstudio

我正在尝试使用shinny来打印图像但由于文件无效而无法正常工作。任何人都可以帮助。

输出:

  

str(filename)中的错误:评估参数'object'时出错   在选择函数'str'的方法时:错误:对象'文件名'不是   结果

以下是代码

installed.packages("shiny")
library(shiny)

shinyUI(fluidPage(

titlePanel(title="Omega Engineering and Design"),
sidebarLayout(position="left",
  sidebarPanel(
    selectInput("drawing","choose the section: ",choices=c("wall cross section","wall cross section 2"),selected = NULL)
   ),

     mainPanel(("Project Avalon"),
            imageOutput("drawing")  ))))
library(png)
library(shiny)


shinyServer(
  function(input,output,session){

 output$drawing=renderImage({

   filename=normalizePath(file.path('./images',paste('wall',input$drawing,'.png',sep='')))

   if(is.null(input$drawing))
     return(NULL)

   if(input$drawing=="wall cross section")
     return(
       list(
         scr= ("C:/Users/Darren Chu/Documents/images/images/wall1.png"),
     fileType="image/png",
         alt=paste("Wall Cross section", input$drawing)

       ))

   else if(input$drawing=="wall cross section 2")
     return(list(
       scr= ("C:/Users/Darren Chu/Documents/images/images/wall2.png"),
 fileType="image/png",
       alt=paste("Wall Cross section", input$drawing)

     ))  
 },deleteFile = F)})

1 个答案:

答案 0 :(得分:0)

您在list()

的来电中输入了拼写错误
list(
  scr= ("C:/Users/Darren Chu/Documents/images/images/wall1.png"),
  fileType="image/png",
  alt=paste("Wall Cross section", input$drawing)
  )

应该是src=...而不是scr=...

这个核心运行:

library(shiny)

ui <- fluidPage(
  titlePanel(title="Omega Engineering and Design"),
  sidebarLayout(position="left",
                sidebarPanel(
                selectInput("drawing","choose the section: ",choices=c("wall cross section","wall cross section 2"),selected = NULL)
                ),
                mainPanel(("Project Avalon"),
                          imageOutput("drawing")  )))


server <- function(input,output,session){
  output$drawing=renderImage({
    filename <- normalizePath(file.path('./images',paste('wall',input$drawing,'.png',sep='')))

    if(is.null(input$drawing))
      return(NULL)

    if(input$drawing=="wall cross section")
      return(
        list(
          src=("Test.png"),
          fileType="image/png",
          alt=paste("Wall Cross section", input$drawing)

        ))

    else if(input$drawing=="wall cross section 2")
      return(list(
        src= ("Test2.png"),
        fileType="image/png",
        alt=paste("Wall Cross section", input$drawing)

      ))  
  },deleteFile = F)}

shinyApp(ui, server)