我已經搜查相當長一段時間了,但我還沒有找到一個解決我的問題不同類型的表格輸入。我建立一個項目管理應用程序,我想使用有光澤,因爲我認爲這將能夠使應用程序更具交互性。[R閃亮:動態創建
因此應用程序的輸入應該在應用程序內完成。輸入將是數字,文本和選擇。對於概述,屬於一起的輸入應排列在一行中。例如:
resource_1,NAME = '共聚焦顯微鏡',鍵入= '機',價格= 1000,價格類型= 'EUR /使用'
我想安排在一個表格中的每個條目。當然,條目的數量是可變的。有時你可能會爲某個項目定義5個資源,有時候是50個。
爲了解決這個問題,我創建了一個閃亮的html表格作爲表格條目。但是,我需要動態訪問這些條目。我想我能做到這一點通過調用的get()函數中的每個表項的輸入ID的字符串。但那不行。
目前:
我可以創建具有不同類型的輸入和行的可變數量的表格。
我可以通過實際調用輸入ID(如「輸入$ element1_1」
相互調用這些輸入,但我不能讓一個循環來自動獲取這些輸入標識的,像get()方法:得到(paste0( '輸入$元素',我, '_',J))
小例子:
library(shiny)
ui =
pageWithSidebar(
headerPanel("TEST"),
sidebarPanel(
helpText("number of resources"),
numericInput("nres","",3,min=0),
actionButton('create_res',"create",icon=icon("plus"),width='100%'),
br(),
br(),
br(),
bsButton('finish_res',"finish",width='100%',style="info"), # check matrix
width=2
),
mainPanel(
uiOutput('matrix_res'),
p("make an entry in row1 col1 and press finish"),
br(),
p("I can extract elements by calling input$element1_1:"),
textOutput('check1'),
br(),
p("but not by searching for the character string with get('element1_1') "),
textOutput('check2')
)
)
server =
function(input,output){
output$matrix_res <- renderTable({
input$create_res #create button dependency
Row_entries <- paste("ressource",1:isolate(input$nres)) #kill nres dependency
Col_entries <- c("text input","number input","selection")
matrix <- data.frame()
for (i in 1:length(Row_entries)) {
matrix[i,1] <- paste0("<input id='element", i, "_", 1, "' class='shiny-bound-input span6' type='text' value=''>")
matrix[i,2] <- paste0("<input id='element", i, "_", 2, "' class='shiny-bound-input span6' type='number' value=''>")
matrix[i,3] <- paste0("<div class='form-group shiny-input-container'>
<div>
<select id='element", i, "_", 3, "' class='form-control'><option value='a' selected>a</option>
<option value='b'>b</option></select>
<script type='application/json' data-for='element", i, "_", 3, "'>{}</script>
</div></div>")
}
colnames(matrix) <- Col_entries
matrix
},sanitize.text.function = identity)
output$check1<-renderText({
input$finish_res
isolate(input$element1_1)
})
output$check2<-renderText({
input$finish_res
isolate(input$get('element1_1'))
})
}
runApp(list(ui = ui, server = server))
運行:您可以通過更改的行數號碼輸入和創建按鈕。您可以通過點擊完成調用ROW1列1的值。
如果您有任何想法如何獲得這些輸入,請回復。我卡在這個狗屎已經一個星期...