[英]Embedded selectInput in DT R Shiny with Large Table
[英]R: Library(Shiny) with Library (DT): Creation of <selectInput> for different colors on Plot
很抱歉给你添麻烦了。 我是 R 编程和一般编程的新手。 95% 的时间,当搜索和阅读在线示例时,我无法理解它们。
我有 shiny 应用程序的代码。 这些代码不是我写的。 这些代码是默认给出的。 当您运行它时,底部表格会出现一个没有颜色的“点” plot。 当您单击特定行时,它所代表的“点”会变为红色。
library(shiny)
library(DT)
ui <- fluidPage(
h3("t1"),
tableOutput("t1"),
hr(),
fluidRow(
column(9, h3("dt1"),
dataTableOutput("dt1")),
column(3, h3("x4"),
verbatimTextOutput("x4"))),
hr(),
fluidRow(
column(8, h3("dt2"),
dataTableOutput("dt2")),
column(4, h3("p5"),
plotOutput("p5")))
)
options(error = function() traceback(2))
server <- function(input, output, session) {
output$t1 <- renderTable(iris[1:10,], striped = TRUE, hover = TRUE)
output$dt1 <- renderDataTable(iris, options = list( pageLength = 5))
output$x4 <- renderPrint({
s = input$dt1_rows_selected
if (length(s)) {
cat('These rows were selected:\n\n')
cat(s, sep = ', ')
}
})
output$dt2 <- renderDataTable(iris,
options = list(pageLength = 5),
server = FALSE)
output$p5 <- renderPlot({
s <- input$dt2_rows_selected
plot(iris$Sepal.Length, iris$Sepal.Width)
if (length(s)) {
points(iris[s, c("Sepal.Length", "Sepal.Width"), drop = F],
pch = 19, cex = 1, col = "red")
}
})
}
shinyApp(ui, server)
问题是,如何为不同的颜色名称创建 selectInput,以便用户可以决定使用哪种颜色,而不仅仅是使用默认的 RED 颜色?
根据我自己的研究,我认为我需要在 UI 中添加 2 行代码并在服务器中编辑 1 行代码。 不幸的是,这些方法虽然不起作用。 用户界面内
selectInput("color", "What is your preferred color?", choices = c("blue", "gold", "green", "pink", "red", "yellow"))
textOutput("color")
在服务器中更改此代码中的“红色”
points(iris[s, c("Sepal.Length", "Sepal.Width"), drop = F],
pch = 19, cex = 1, col = "red")
到“输入$颜色”
points(iris[s, c("Sepal.Length", "Sepal.Width"), drop = F],
pch = 19, cex = 1, col = "input$color")
当我想给我的图上色时(通过选择表 dt2 中的行)
invalid color name 'input$color'
很抱歉给大家添麻烦了。 我知道你们中的大多数人都忙于自己的生活,我非常感谢所提供的任何帮助或建议。
问题是"input$color"
应该是input$color
(没有引号)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.