【发布时间】:2014-09-23 17:18:14
【问题描述】:
只是发现了闪亮的应用程序,但这让我发疯了......我查看了许多 server.R 和 ui.R 代码的示例,但无法弄清楚我做错了什么。如果这是非常基本的事情,请提前道歉............
以 iris 数据集为例,我想将一列与另一列进行对比,使用 qplot 或者最好是 ggplot 进行一些简单的操作
但是,使用 qplot 我得到了这个:
并使用 ggplot2,我得到了错误:
我认为我不需要响应函数,因为我没有对数据集进行子集化,只是提取要绘制的列。
server.R 代码
library(shiny)
library(shinyapps)
library(ggplot2)
shinyServer(function(input, output, session) {
output$text1 <- renderText({input$id1})
output$text2 <- renderText({input$select1})
output$plot1 <- renderPlot({
g <- qplot(Sepal.Length, input$select1, data = iris)
print(g)
})
})
或者使用ggplot函数代替qplot调用
g <- ggplot(iris, aes(x = Sepal.Length, y = input$select1))
g <- g + geom_line(col = "green", lwd =1) +
labs(x = "Date", y = "Ranking") +
theme_bw() + scale_y_reverse()
ui.R 代码
library(shiny)
library(shinyapps)
data(iris)
opts <- unique(colnames(iris))
opts <- opts[-1] ## want to keep Sepal.Length as the x values
shinyUI(pageWithSidebar(
headerPanel('test with iris database'),
sidebarPanel(
selectInput(inputId = "select1", label = "select",
choices = opts),
textInput(inputId = "id1", label = "Input Text", "")
),
mainPanel(
p('Output text1'),
textOutput('text1'),
textOutput('text2'),
plotOutput('plot1')
)
))
【问题讨论】:
标签: r shiny shiny-server