我有一个简单的闪亮应用
#ui.r
navbarPage(
"Application",
tabPanel("General",
sidebarLayout(
sidebarPanel(
uiOutput("tex2")
),
mainPanel(
DT::dataTableOutput("hot3")
)
)))
#server.r
library(shiny)
library(DT)
library(tidyverse)
server <- function(input, output,session) {
output$tex2<-renderUI({
numericInput("text2","Rows selected",
value = input$hot3_rows_selected,
min=0
)
})
output$hot3 <-DT::renderDataTable(
iris %>% rowid_to_column("Row") %>% mutate(Row = ""),
rownames = FALSE,
extensions = "Select",
options = list(
columnDefs = list(list(className = "select-checkbox", targets = 0, orderable = FALSE)),
select = list(style = "multi", selector = "td:first-child")
))
}
我有一个numericInput()
,它通常应显示数据表中所选行的数量,但是如您所见,它仅显示所选的第一行,而不显示它们的数量。
答案 0 :(得分:1)
要显示所选的行数,您需要使用input$hot3_rows_selected
的长度(改为使用length(input$hot3_rows_selected)
)。
library(shiny)
ui <- navbarPage(
"Application",
tabPanel("General",
sidebarLayout(
sidebarPanel(uiOutput("tex2")),
mainPanel(DT::dataTableOutput("hot3"))
)
)
)
server <- function(input, output,session) {
library(tidyverse)
output$tex2 <- renderUI({
numericInput("text2", "Rows selected",
value = length(input$hot3_rows_selected),
min = 0)
})
output$hot3 <- DT::renderDataTable(
iris %>%
rowid_to_column("Row") %>%
mutate(Row = ""),
rownames = FALSE,
extensions = "Select",
options = list(
columnDefs = list(list(className = "select-checkbox", targets = 0, orderable = FALSE)),
select = list(style = "multi", selector = "td:first-child")
)
)
}
shinyApp(ui, server)