DT包允许您使用来获取选定行的索引input$tableID_rows_selected。这对于没有过滤数据的表非常有用。但是,如果我们有一个经过过滤的数据集,则由于行索引已关闭,因此无法使用相同的方法。
那么,对于过滤后的数据集,我们如何在数据表的选定行中获取数据?
在下面,我发布了一个基本的闪亮应用程序,其中显示了四个表:第一个是原始mtcars数据集,第二个是在第一个中获取选定的行。第三和第四做相同的事情,但是在“过滤器” sliderInput上过滤了数据集之后。
library(shiny)
library(DT)
library(dplyr)
ui <- fluidPage(
DT::dataTableOutput("origTable"),
DT::dataTableOutput("origTableSelected"),
sliderInput("filter", label = "Filter by cyl", min = 4, max = 8, step = 2, value = 6),
DT::dataTableOutput("filteredTable"),
DT::dataTableOutput("filteredTableSelected")
)
server <- function(input, output, session) {
output$origTable <- DT::renderDataTable({
datatable(
mtcars,
selection = list(mode = "multiple"),
caption = "Original Data"
)
})
origTable_selected <- reactive({
ids <- input$origTable_rows_selected
mtcars[ids,]
})
output$origTableSelected <- DT::renderDataTable({
datatable(
origTable_selected(),
selection = list(mode = "multiple"),
caption = "Selected Rows from …Run Code Online (Sandbox Code Playgroud) 如果你想在普通的闪亮应用程序中包含图像,你可以调用
shiny::img(src = "imgName.png")
Run Code Online (Sandbox Code Playgroud)
在您的 ui 函数中具有以下目录结构:
| shinyApp/
| ui.R
| server.R
| www/
| myImage.png
Run Code Online (Sandbox Code Playgroud)
如何在一个闪亮的应用程序(也是一个 r 包)中复制它?我尝试以完全相同的方式执行所有操作,但使用以下目录结构,但没有成功:
| packageName/
| R
| app.R # contains ui.R and server.R
| inst
| www
| imgName.png
Run Code Online (Sandbox Code Playgroud)
就其价值而言,就我而言,该包实际上捆绑了一个闪亮的模块,但我认为这与此问题无关。
Suppose I have some set of lines that I plot using ggplot and geom_line. I want to label these lines. I can do this using geom_dl from the directlabels package, but even with the provided method to avoid overlaps (e.g. "last.qp"), I still think that the labels are two close together.
How can I increase the spacing between these labels (here, in the y direction), without manually specifying each of their locations using ggplot2::annotate or something similar? I'm …
在我的应用程序中,我将一个模块嵌套在另一个模块中。父模块和子模块都使用 renderUI(滑块)创建 UI 输出,并根据此滑块的值过滤显示在 ggplot 上的数据。我熟悉常规用户界面/服务器情况下的这种模式 - 但是,我不确定如何在模块中访问滑块的值。
下面的代码显示了我对 UI 调用的模块和嵌套模块执行此操作的尝试。
library(shiny)
library(dplyr)
library(ggplot2)
ui <- fluidPage(
fluidRow(
outerModUI("outer")
)
)
outerModUI <- function(id) {
ns <- NS(id)
fluidPage(fluidRow(
uiOutput(ns("outer_slider")),
plotOutput(ns("outer_plot")),
innerModUI(ns("inner"))
))
}
innerModUI <- function(id) {
ns <- NS(id)
fluidPage(fluidRow(
uiOutput(ns("inner_slider")),
plotOutput(ns("inner_plot"))
))
}
server <- function(input, output, session) {
callModule(outerMod, "outer")
output$outer_slider <- renderUI({
sliderInput("slider1", label = "outer slider", min = round(min(mtcars$mpg)),
max = round(max(mtcars$mpg)), value = c(min(mtcars$mpg), max(mtcars$mpg), step = 1))
})
output$outer_plot <- …Run Code Online (Sandbox Code Playgroud)