我确定没有人帮助过我,tk。我只是 asked the question之前不是很正确。 我正在尝试创建一个 FlexDashcoard 应用程序。要了解该程序的工作原理,您需要 sample data files我已经准备好了。对于文件中的俄语字符,我提前表示歉意,它们是“按原样”呈现给您的。
这是我的代码:
---
title: "AFEA of Russian enterprises"
output:
flexdashboard::flex_dashboard:
storyboard: true
orientation: rows
vertical_layout: fill
theme: simplex
runtime: shiny
---
```{r GlobalOptions}
options(knitr.duplicate.label = 'allow')
rv <- reactiveValues(txt_file = FALSE)
OKVEDselectInputChoices<- reactiveValues(data = NULL)
```
```{r setup, include=FALSE, echo=FALSE, message=FALSE}
### Library connection module ###
library("flexdashboard")
library("dygraphs")
library("shiny")
library("shinyFiles")
library("DT")
library("ggplot2")
library("dplyr")
library("here")
library("data.table")
library("plyr")
### ----------------------------- ###
```
## Sidebar {.sidebar}
```{r}
roots <- c('C' = 'C:/', 'D' = 'D:/', '//' = '\\\\ns\\Public\\Power BI')
renderUI({
shinyFilesButton("files_choose", "Select files", "",
multiple=TRUE,
buttonType = "default",
class = NULL,
icon = icon("list-alt"),
style = "background-image: linear-gradient(#D9230F, #D9230F 6%, #D9230F);
border-color: #A91B0C;
margin-top: 10px;
width: 100%;
float: left;
box-sizing: border-box;",
viewtype = "detail"
)
})
br()
renderUI({
actionButton(inputId = "apply",
label = "Apply",
icon = icon("play"),
style = "background-image: linear-gradient(#D9230F, #D9230F 6%, #D9230F);
border-color: #A91B0C;
margin-top: 10px;
margin-bottom: 10px;
width: 100%;
float: left;
box-sizing: border-box;"
)
})
br()
renderUI({h6(inputId="sideBarText2", "Выбор ОКВЭД(ов):")})
renderUI({
selectInput("OKVEDlectInput",
label = NULL,
choices = OKVEDselectInputChoices$data,
#selected = "Percent White")
multiple=TRUE
)
})
```
```{r}
shinyFileChoose(input, "files_choose",
roots=roots,
filetypes=c('csv'))
rv_result <- eventReactive(
input$apply,{
if (!is.null(input$files_choose))
{
myInputFile <- parseFilePaths(roots,input$files_choose)$datapath
all.files <- myInputFile
print(all.files)
a.vector <- grep("data\\-\\d+\\-structure\\-", all.files, ignore.case = TRUE)
print(a.vector)
all.files <- all.files[a.vector]
all.files<- sort(all.files)
n <- length(all.files)
print(n)
data = vector('list', n)
if (n>0) {
for (i in 2:(n+1)) {
#print(paste("Вот такой файл:" , all.files[i-1]))
data[i-1] <- lapply(all.files[i-1],
fread,
showProgress = TRUE,
sep = ";",
quote = "",
header = FALSE,
stringsAsFactors=TRUE,
select = c(1:124))
}
}
}
table <- rbindlist(data)
UN <- unique(table[[5]])
UN <- sort(UN)
OKVEDselectInputChoices$data <- UN
rv$txt_file <- table
rv_result <- rv$txt_file
#View(rv$txt_file)
}
)
```
### Basic information
```{r}
#renderTable({
# dataset <- rv_result()
# dataset
#})
f <- function(verlist, list_for_ver, resulttyp=0,delna=1) {
# verlist - массив, который требуется проверить на совпадение с элементами второго массива
# list_for_ver - проверочный массив, т.е. тот, с которым сравнимается
# resulttyp (0 - выводятся номера элементов list_for_ver, которые найдены);
# (1 - выводятся найденные значения)
# delna - (0 -если элемент не найде, то он не показывается)
# (1 -если элемент не найде, то указывается NA)
listforreturn <- vector(mode = 'list', length=0)
if ((class(verlist)=='list') && (class(list_for_ver)=='list')){
if (delna==1){
listforreturn <- as.vector(na.omit(match(verlist,list_for_ver)))
}
else{
listforreturn <- as.vector(match(verlist,list_for_ver))
}
if (resulttyp==0){
listforreturn <- as.list(listforreturn)
}
else{
listforreturn<- as.list(list_for_ver[listforreturn])
}
}
return(listforreturn)
}
dataset <- reactive({rv_result()})
renderUI({
data <- dataset()
if (is.null(input$OKVEDlectInput)) {
data <- dataset()
}
else{
d1 <- as.list(input$OKVEDlectInput)
d2 <- as.list(as.vector(data$V5))
result <- which(!is.na(f(d2, d1,0,0)))
result <- as.vector(result)
data <- data[result,]
}
div(HTML("География анлиза насчитывает "),
datatable(data, fillContainer=getOption("DT.fillContainer", TRUE)))
})
```
### Secondary information
Some commentary about Frame 2.
You can download the finished version of the code
我的应用程序首先创建一个界面,允许用户选择要导入的文件(或多个),但具有特定名称,并将这些数据加载到应用程序中。
在这一行中,我创建了一个映射:
div(HTML("География анлиза насчитывает "),
datatable(data, fillContainer=getOption("DT.fillContainer", TRUE)))
看起来很奇怪。如果不添加fillContainer=getOption("DT.fillContainer", TRUE)
,则滚动条从表格中消失。当您添加此元素时,所有内容都会缩小到非常窄的尺寸:
我无法将表格拉伸(stretch)到底部以获得剩余的可用空间。
我特地准备了一个简短版的代码,从中可以看出问题是亲切的,使用现成的数据数组很容易重复。
---
title: "AFEA of Russian enterprises"
output:
flexdashboard::flex_dashboard:
storyboard: true
orientation: rows
vertical_layout: fill
theme: simplex
runtime: shiny
---
```{r setup, include=FALSE, echo=FALSE, message=FALSE}
library("flexdashboard")
library("DT")
```
## Sidebar {.sidebar}
-------------------------------------
```{r}
```
### Chart A
```{r}
renderUI({
data <- iris
div(HTML("География анлиза насчитывает "),
datatable(data, fillContainer=getOption("DT.fillContainer", TRUE)))
})
```
最佳答案
您可以使用 css 来增加/减少数据表的宽度和高度。我在 div
中添加了 style = "height: 175%"
以增加高度。
---
title: "AFEA of Russian enterprises"
output:
flexdashboard::flex_dashboard:
storyboard: true
orientation: rows
vertical_layout: fill
theme: simplex
runtime: shiny
---
```{r setup, include=FALSE, echo=FALSE, message=FALSE}
library("flexdashboard")
library("DT")
```
## Sidebar {.sidebar}
-------------------------------------
```{r}
```
### Chart A
```{r}
renderUI({
data <- iris
div(HTML("География анлиза насчитывает "),
datatable(data, fillContainer=getOption("DT.fillContainer", TRUE)), style = "height: 175%")
})
```
关于html - 如何在开发 FlexdashBoard 应用程序时在 renderUI 中结合数据表和 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67745390/