我是新的翻译R代码,我试图获得一个有光泽的反应轮廓图,但我不能这样做: 服务器的代码是:
library(shiny)
library(latticeExtra)
shinyServer(function(input, output) {
grid<-expand.grid(a = seq(10, 15, 0.1),b = seq(50, 150,10))
grid$c=grid$a*grid$b/100
output$y<-renderPlot(contourplot( c ~ a + b, data= grid ,cuts = 20, label = TRUE,
xlim = c( input$Min_a, input$Max_a), ylim= c(input$Min_b,input$Max_b)))
})
对于UI
library(shiny)
library(latticeExtra)
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
textInput("Min_a","Enter Minimum a:",""),
textInput("Max_a","Enter Maximum a:",""),
textInput("Min_b","Enter Minimum b:",""),
textInput("Max_b","Enter Maximum b:","")
),
mainPanel(
plotOutput("y")
)
)
))
不要工作。我尝试把de lim与一个数字和工作,但这不是我尝试做的。服务器中的修改如下所示:
output$y<-renderPlot(contourplot( TAzH ~ rto + TCH, data= grid ,cuts = 20, label = TRUE,
xlim = c(10,15), ylim= c(50,130)))
任何人都可以帮助我。先感谢您。 对不起,因为我的英语非常糟糕。
答案 0 :(得分:0)
你需要将xlim和ylim转换为整数(它们从UI中作为字符串出现,然后它将起作用)。您对contourPlot的输入需要是动态的。此外,在UI输入中有一些默认值:
server <- shinyServer(function(input, output) {
output$y<-renderPlot({
grid <- expand.grid(a = seq(as.integer(input$Min_a), as.integer(input$Max_a), 0.1),b = seq(as.integer(input$Min_b), as.integer(input$Max_b,10)))
grid$c = grid$a*grid$b/100
#contourplot(c ~ a + b, data= grid, cuts = 20, label = TRUE, xlim=c(10,15), ylim=c(50,150,10))
contourplot(c ~ a + b, data= grid, cuts = 20, label = TRUE,
xlim = c(as.integer(input$Min_a), as.integer(input$Max_a)),
ylim= c(as.integer(input$Min_b), as.integer(input$Max_b)))
})
})
library(shiny)
library(latticeExtra)
ui <- shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
textInput("Min_a","Enter Minimum a:","10"),
textInput("Max_a","Enter Maximum a:","15"),
textInput("Min_b","Enter Minimum b:","50"),
textInput("Max_b","Enter Maximum b:","150")
),
mainPanel(
plotOutput("y")
)
)
))
shinyApp(ui=ui, server=server)