本文介绍了R闪亮:动力大小的情节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 这是我的代码: $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ sliderInput(height,Plot Height,min = 10,max = 20,value = 15)) mainPanel( plotOutput(plot ,width =15cm,height =15cm))} 我设置15厘米只是为了看情节。 我尝试了不同的方法来从sliderInputs获取数据并将其带入plotOutput。我尝试input.height,input $ heigt,但没有任何工作。解决方案您必须使用服务器中的输入这里有一个解决方案: 宽度和高度的单位必须是一个有效的CSS单位,我不知道cm是有效的,使用%或px(或int,它会被强制为一个字符串,px在结尾) )runApp( ui = pageWithSidebar( headerPanel(Test), sidebarPanel( sliderInput width,Plot Width(%),min = 0,max = 100,value = 100), sliderInput(height,Plot Height(px),min = 0,max = ,value = 400)), mainPanel( uiOutput(plot.ui))), server = function(input,输出,会话){ 输出$ plot.ui< - renderUI({ plotOutput(plot,width = paste0(input $ width,%),heigh t =输入$ height)}) 输出$ plot plot(1:10)})} )) I wanna have a plot with dynamic size and all should happen in the shinyUI.Here is my code: shinyUI{ sidebarPanel( sliderInput("width", "Plot Width", min = 10, max = 20, value = 15), sliderInput("height", "Plot Height", min = 10, max = 20, value = 15) ) mainPanel( plotOutput("plot", width="15cm", height="15cm") ) }I set "15cm" only to see the plot.I tried different methods to take the data from the sliderInputs and bring it to the plotOutput. I tried "input.height", "input$heigt" but nothing worked. 解决方案 You must use the inputs in the server side, for example here is one solution :And the unit of the width and height must be a valid CSS unit, i'm not sure that "cm" is valid, use "%" or "px" (or an int, it will be coerced to a string with "px" at the end)library(shiny)runApp(list( ui = pageWithSidebar( headerPanel("Test"), sidebarPanel( sliderInput("width", "Plot Width (%)", min = 0, max = 100, value = 100), sliderInput("height", "Plot Height (px)", min = 0, max = 400, value = 400) ), mainPanel( uiOutput("plot.ui") ) ), server = function(input, output, session) { output$plot.ui <- renderUI({ plotOutput("plot", width = paste0(input$width, "%"), height = input$height) }) output$plot <- renderPlot({ plot(1:10) }) })) 这篇关于R闪亮:动力大小的情节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 16:29