小编Chr*_*hee的帖子

在Shiny R中重置DT :: renderDataTable()的行选择

我再现了由Yihui Xie编写的一个闪亮的应用程序示例(https://yihui.shinyapps.io/DT-rows/).该应用程序使用DT::renderDataTable()允许行选择.

一切都很好.然而,我想知道是否可以重置行选择(即撤消点击选择)?我已经尝试使用操作按钮重置s = input$x3_rows_selected(请参阅下面的脚本).

使用我当前的脚本,s = input$x3_rows_selected确实会被清空,但我可以不重新填充它.此外,所选行仍然被点击(阴影)

有没有人有想法?DT :: renderDataTable()中是否有一个选项来重置选择?或者有没有人有解决方法的想法?

谢谢!

我的修改(操作按钮)示例表单https://yihui.shinyapps.io/DT-rows/):

server.R

library(shiny)
library(DT)

shinyServer(function(input, output, session) {


    # you must include row names for server-side tables
    # to be able to get the row
    # indices of the selected rows
    mtcars2 = mtcars[, 1:8]
    output$x3 = DT::renderDataTable(mtcars2, rownames = TRUE, server = TRUE)

    # print the selected indices

    selection <- reactive({
        if (input$resetSelection) 
            vector() else input$x3_rows_selected
    }) …
Run Code Online (Sandbox Code Playgroud)

r shiny

8
推荐指数
1
解决办法
6130
查看次数

Shiny R:fluidRow中不需要的空白区域

我正在使用fluidRow/Column布局创建一个闪亮的应用程序!

在第一行中,我想包含一个包含一个图像图的输出!第二行包含更多绘图和无功输入(selectInput).

无论我尝试什么(renderPLot,renderImage,renderUI)来返回绘图,我总是在第一行下面的一个空白处打开行 - .-

请注意,我为第一行中的绘图提供了绘图功能.情节本身看起来很完美,它只是情节下方的白色空间......

有什么建议可能是这种行为的原因以及如何摆脱空白?

谢谢 !

Server.R

source("plotFunction.R")

shinyServer(function(input, output) {

   output$plot1 <- renderImage({

         outfile <- tempfile(fileext='.png')
         png(outfile, width=400, height=150)
         plotFunction(col_palette = heat.colors(4))
         dev.off()


         # Return a list containing the filename
         list(src = outfile,
                  contentType = 'image/png',
                  width = 400,
                  height = 150)

  }, deleteFile = TRUE)  # end of render image

}) # end of shinyServer  
Run Code Online (Sandbox Code Playgroud)

UI.R

shinyUI(fluidPage(

   # 1st row
  fluidRow(
             column(   12, 
                       align = "center",
                       imageOutput("plot1")
              ) # end of column
), # end …
Run Code Online (Sandbox Code Playgroud)

r shiny

5
推荐指数
1
解决办法
3520
查看次数

将 tidyr complete() 与变量中指定的列名一起使用

我在使用tidyr::complete()带有列名作为变量的函数时遇到问题。

内置示例按预期工作:

df <- data_frame(
 group = c(1:2, 1),
 item_id = c(1:2, 2),
 item_name = c("a", "b", "b"),
 value1 = 1:3,
 value2 = 4:6
)

df %>% complete(group, nesting(item_id, item_name)) 
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试将列名作为字符串提供时,它会产生错误。

gr="group"
id="item_id"
name="item_name"
df %>% complete_(gr, nesting_(id, name),fill = list(NA))
Run Code Online (Sandbox Code Playgroud)

r tidyr

5
推荐指数
2
解决办法
717
查看次数

通过申请避免循环 - 值得麻烦吗?

我写了一个Rscript来以一种理想的格式提供一些数据.特别是我只想重新排列数据集,最终得到8行12列(96孔板格式).我嵌套了两个for循环,工作得非常好:

element1 = seq(1,96,1)
element2 = seq(0.5,48,0.5)
df = data.frame(element1,element2)
storage = data.frame(matrix(NA,nrow = 8, ncol = 12))
container = vector("list",ncol(df))

for (n in 1:ncol(df)){
      j = 0  
        for (i in seq(1,length(df[,n]),12)) { 
              j = j+1
              storage[j,] = df[(i):(i+11),n]  
          }
     container[[n]]=storage

}
Run Code Online (Sandbox Code Playgroud)

备注:我将数据打包在列表中以便于在.xls中导出.
我知道这是一种非常简单的方法......但它有效

然而,我愿意学习:-)因为我读了很多,应该避免使用循环并使用"apply"与函数组合.我尝试使用apply和函数来解决任务.但是我无法得到结果,函数的使用和应用对我来说似乎要复杂得多.因此,总是值得避免循环吗?如果是的话,你会怎么做?

谢谢,克里斯蒂安

r

4
推荐指数
1
解决办法
112
查看次数

R:将substr应用于dataframe列的每个元素

这是我的情况:我有一个数据帧,我想将substr函数应用于特定列的每个元素.我要操纵的列包含如下表达式:

x = c("name1_01", "name2_02", "name3_01")
df = data.frame(x)
colnames(df) = ("Names")
df["Names"] = sapply(df["Names"], as.character)
df
# Names
# 1 name1_01
# 2 name2_01
# 3 name3_01
Run Code Online (Sandbox Code Playgroud)

现在我想要删除特定列中每个条目的最后3位数字.我只是尝试了substr,这不是我想要的东西:

df["Names"] = substr(df["Names"], 1,5)
df["Names"]
# Names
# 1 c("name1
# 2 c("name1
# 3 c("name1
Run Code Online (Sandbox Code Playgroud)

但是,如果我将substr应用于单个元素,我会得到正确的结果:

df[1,"Names"] = substr(df[1,"Names"], 1,5)
df[1,"Names"]
# Names
# [1,] "name1"
Run Code Online (Sandbox Code Playgroud)

我已经尝试过很多东西(我也尝试过为子目录而烦恼)但是我没有得到它.我对R很新,希望解决方案很明显......

谢谢你们所有人,克里斯!

r

2
推荐指数
2
解决办法
8277
查看次数

R 闪亮的 updateSelectizeInput 标签的自定义 HTML 标签

有没有办法将 HTML 标签(例如 h6)用于 updateSelectizeInput(适用于 selectInput,请参阅下面的代码)?在下面的代码中,只需在 updateSelectizeInput [object Object] 中使用 h6("Label") 即可显示为输出。

rm(list = ls())
library(shiny)



ui =fluidPage(
  selectizeInput('DropDownSelectize',choices=NULL,label=""),
  selectInput('DropDownSelect',choices = c("choice1","choice2","choice3"),
  label=h6("Label"))
 )

server = function(input, output, session) {

 observe({
   updateSelectizeInput(session, 
                     'DropDownSelectize',
                      label = h6("Label"),
                      choices = c("choice1","choice2","choice3"),
                      selected = "choice1",
                      server = TRUE)

 })


}
runApp(list(ui = ui, server = server))
Run Code Online (Sandbox Code Playgroud)

谢谢

shiny selectize.js

2
推荐指数
1
解决办法
1296
查看次数

标签 统计

r ×5

shiny ×3

selectize.js ×1

tidyr ×1