为了账号安全,请及时绑定邮箱和手机立即绑定

使用闪亮动态地将图添加到网页

/ 猿问

使用闪亮动态地将图添加到网页

收到一只叮咚 2019-11-14 15:30:06

我想使用闪亮的动态创建绘图的应用程序添加到页面。它可能是10个地块,也可能只有一个。我在动态UI的闪亮主页中使用了本教程。


这是一个简化的示例。该函数showme正在绘制图形


服务器

shinyServer(function(input, output) {

  # Create an environment for storing data

  symbol_env <- new.env()

  # Make a chart for a symbol, with the settings from the inputs

  make_chart <- function(symbol) {

    showme(symbol)

  }


  display <- c("1083484" , "1101732")


  output$MyList <- renderUi({ 

    for (i in i:nrow(display))

       renderPlot({make_chart(display[i])})

    })

})

用户界面

shinyUI(pageWithSidebar(

  headerPanel("My Plots !"),

  sidebarPanel(

    wellPanel(

      p(strong("Scan1"))))

 ,mainPanel(

      uiOutput("MyList")

)))

我收到以下错误


Listening on port 8100

Error in .subset2(x, "impl")$defineOutput(name, value, deparse(substitute(value))) : 

  Unexpected character output for display

如果不是这样-我将不胜感激。谢谢。


> sessionInfo()

R version 2.15.3 (2013-03-01)

Platform: i386-w64-mingw32/i386 (32-bit)


查看完整描述

3 回答

?
天涯尽头无女友

也许由于Winston Chang的这个例子很有帮助:


带有动态地块数量的闪亮示例应用程序


这是完整的示例,仅在使用linkrot的情况下:


服务器


max_plots <- 5


shinyServer(function(input, output) {


# Insert the right number of plot output objects into the web page

output$plots <- renderUI({

  plot_output_list <- lapply(1:input$n, function(i) {

     plotname <- paste("plot", i, sep="")

     plotOutput(plotname, height = 280, width = 250)

   })


   # Convert the list to a tagList - this is necessary for the list of items

   # to display properly.

   do.call(tagList, plot_output_list)

})


# Call renderPlot for each one. Plots are only actually generated when they

# are visible on the web page.

for (i in 1:max_plots) {

    # Need local so that each item gets its own number. Without it, the value

    # of i in the renderPlot() will be the same across all instances, because

    # of when the expression is evaluated.

    local({

        my_i <- i

        plotname <- paste("plot", my_i, sep="")


        output[[plotname]] <- renderPlot({

        plot(1:my_i, 1:my_i, xlim = c(1, max_plots), ylim = c(1, max_plots), main = paste("1:", my_i, ".  n is ", input$n, sep = ""))

        })

    })

}

})

用户界面


shinyUI(pageWithSidebar(


  headerPanel("Dynamic number of plots"),


    sidebarPanel(

      sliderInput("n", "Number of plots", value=1, min=1, max=5)

    ),


    mainPanel(

      uiOutput("plots") # This is the dynamic UI for the plots

    )

))


查看完整回答
反对 回复 2019-11-14
?
繁花不似锦

要回答上面的评论中有关如何动态返回对象列表(例如,图,表和文本)的问题,可以在renderUI中的div标签中生成适当输出的列表,然后与for循环中的相应渲染函数匹配。例如:


max_plots <- 5


shinyServer(function(input, output) {


# Insert the right number of plot output objects into the web page

output$plots <- renderUI({

  plot_output_list <- lapply(1:input$n, function(i) {

     plotname <- paste("plot", i, sep="")

     plottitle <- paste("plottitle", i, sep="")

     tablename <- paste("tablename", i, sep="")

     tags$div(class = "group-output",

       textOutput(plottitle, container = h3),

       plotOutput(plotname, height = 280, width = 250),

       tableOutput(tablename)

     )

   })


   # Convert the list to a tagList - this is necessary for the list of items

   # to display properly.

   do.call(tagList, plot_output_list)

})


# Call renderPlot for each one. Plots are only actually generated when they

# are visible on the web page.

for (i in 1:max_plots) {

    # Need local so that each item gets its own number. Without it, the value

    # of i in the renderPlot() will be the same across all instances, because

    # of when the expression is evaluated.

    local({

        my_i <- i

        plotname <- paste("plot", my_i, sep="")

        plottitle <- paste("plottitle", my_i, sep="")

        tablename <- paste("tablename", my_i, sep="")


        output[[plotname]] <- renderPlot({

        plot(1:my_i, 1:my_i, xlim = c(1, max_plots), ylim = c(1, max_plots), main = paste("1:", my_i, ".  n is ", input$n, sep = ""))

        })

        output[[plottitle]] <- renderText({paste("1:", my_i, ".  n is ", input$n, sep = "")

        })

        output[[tablename]] <- renderTable({table(x = 1:my_i, y = 1:my_i)

        })

    })

}

})

希望对您有所帮助!


查看完整回答
反对 回复 2019-11-14
?
侃侃无极

使用闪亮的动态添加N个图:


runApp(

list(

ui = fluidPage(

  headerPanel('Tittle'),


  sidebarPanel(

    fileInput('file1', 'Choose File:'),

    textInput("target", label="Target", value="Choose target"),

    actionButton("addButton", "Go!"),

    p('The button start the code server'),

    p("This is UI")


  ),


  mainPanel(


    uiOutput("plots")

  )),

#SERVER

server = function(input, output) {     

  dataset <- eventReactive(input$addButton, {


    #Obtain the file and textinput

    inFile <- input$file1

    df <- read.csv(inFile$datapath)

    df$target <- input$target

    return(df)


  })


  output$plots <- renderUI({



    df <- dataset()

    n <- df$target[1]


    plot_output_list <- lapply(1:n, function(i) {


      plotname <- paste("plot", i, sep="")

      plotOutput(plotname, height = 580, width = 550)



    })



    do.call(tagList, plot_output_list)



  })

  observe({             


    for (i in 1:length()) {

      local({ 



        plotname <- paste("plot", i, sep="")


        output[[plotname]] <- renderPlot({


          #function_plot is the function generate plot

          function_plot()


        })

      })#endlocal

    }


  })

}

  )

)

https://github.com/ericbellet/recomendacion-modelos/blob/master/shiny/generate_rocSHINY.R


查看完整回答
反对 回复 2019-11-14
  • 3 回答
  • 0 关注
  • 41 浏览
我要回答

相关问题推荐

添加回答

回复

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信