使用Shinyjs和googlesheets重置闪亮的小部件
我的应用程序接收用户输入并将其存储在谷歌工作表中。我希望有一个操作按钮,当单击按钮时,该按钮可以重置所有侧栏面板ui输入。我用shinyjs试了一下,但每次按下按钮都会出现灰色屏幕。我还尝试使用3种不同的Shinyjs ObserveeEvent重置分别重置每个小部件。我的问题是,用于捕获位置的“运行JS代码”是否会干扰侧面板的重置 服务器使用Shinyjs和googlesheets重置闪亮的小部件,shiny,shinyjs,r-googlesheets,Shiny,Shinyjs,R Googlesheets,我的应用程序接收用户输入并将其存储在谷歌工作表中。我希望有一个操作按钮,当单击按钮时,该按钮可以重置所有侧栏面板ui输入。我用shinyjs试了一下,但每次按下按钮都会出现灰色屏幕。我还尝试使用3种不同的Shinyjs ObserveeEvent重置分别重置每个小部件。我的问题是,用于捕获位置的“运行JS代码”是否会干扰侧面板的重置 服务器 shinyServer(功能(输入、输出、会话){ 输出$distPlot您有输入错误:selected=NULLselected=“NULL”for se
shinyServer(功能(输入、输出、会话){
输出$distPlot您有输入错误:selected=NULL
selected=“NULL”for selectInput默认为列表中的第一项。我希望它为空,因此“”实际上是我列表中的一个名称。我尝试了它,但不管怎样,如果我将其更改为selected为“NULL”,则会出现相同的问题。删除双引号会使代码正常工作。。。
library(shiny)
library(googlesheets)
library(dplyr)
library(shinyjs)
shinyUI(fluidPage(
titlePanel(""),
sidebarLayout(
sidebarPanel(
shinyjs::useShinyjs(),
id = "side-panel",
selectInput("names",
"Name:",c(" ","Steve","Bob","Sally"),selected=" "),
radioButtons("radio", "",
c("Checking In" = "In","Heading Out" = "Out"),
selected="NULL"),
textInput("destination","Notes"),
actionButton("capture", "Share Location"),
tags$hr(),
actionButton("submit","Submit")
),
mainPanel(
textOutput("distPlot"),
verbatimTextOutput("lat"),
verbatimTextOutput("long"),
tableOutput("Table")
#verbatimTextOutput("geolocation")
)
)
)
)
shinyServer(function(input, output,session) {
output$distPlot <- renderText({
x= if(input$names=="Steve") {
print(gs_edit_cells(safety, ws = "Sheet1",input=input$names, anchor = "A2"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$destination, anchor = "B2"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$radio, anchor = "C2"))
print(gs_edit_cells(safety, ws = "Sheet1",input=format(Sys.time(), "%a %D %X"), anchor = "D2"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$lat, anchor = "E2"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$long, anchor = "F2"))
} else if (input$names=="Bob"){
print(gs_edit_cells(safety, ws = "Sheet1",input=input$names, anchor = "A3"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$destination, anchor = "B3"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$radio, anchor = "C3"))
print(gs_edit_cells(safety, ws = "Sheet1",input=format(Sys.time(), "%a %D %X"), anchor = "D3"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$lat, anchor = "E3"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$long, anchor = "F3"))
} else if (input$names=="Sally"){
print(gs_edit_cells(safety, ws = "Sheet1",input=input$names, anchor = "A4"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$destination, anchor = "B4"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$radio, anchor = "C4"))
print(gs_edit_cells(safety, ws = "Sheet1",input=format(Sys.time(), "%a %D %X"), anchor = "D4"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$lat, anchor = "E4"))
print(gs_edit_cells(safety, ws = "Sheet1",input=input$long, anchor = "F4"))
} else {
print()
}
})
observeEvent(input$submit, {
shinyjs::reset("side-panel")
})
observeEvent(input$capture, {
# Run JS code to get location
runjs('
$(document).ready(function () {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
function onError (err) {
Shiny.onInputChange("geolocation",false);
}
function onSuccess (position) {
setTimeout(function () {
var coords = position.coords;
console.log(coords.latitude + ", " + coords.longitude);
Shiny.onInputChange("geolocation", true);
Shiny.onInputChange("lat", coords.latitude);
Shiny.onInputChange("long", coords.longitude);
}, 1100)
}
});
')
})
output$lat <- renderPrint({
input$lat
})
output$long <- renderPrint({
input$long
})
})