这是我的代码:
library(shiny)
library(shinydashboard)
library(ECharts2Shiny)
library(ggplot2)
library(dplyr)
library(shinyjs)
demo <- data.frame(c(5,0,0,1,20,25,14,1,53),
c(1,1,1,2,12,22,5,1,25),
c(6,0,0,3,26,38,19,2,65),
c(0,0,0,0,5,3,0,0,6),
c(0,1,1,0,1,6,0,0,7),
c(6,0,1,3,32,47,19,2,78),
c(2,0,0,1,8,13,10,1,33),
c(0,0,0,0,0,9,2,0,4),
c(1,0,0,1,6,4,6,0,23))
names(demo) <- c("M", "F", "O", "B", "C", "Re", "Vi", "Ac", "Co")
row.names(demo) <- c("Az","Bh", "Bi", "Ch", "Ha", "Ka", "N.G", "Ra", "Su")
ui <- shinyUI(dashboardPage(
dashboardHeader(title = "reset example"),
dashboardSidebar(tags$img(src="bar.PNG", style ="text-align:center;")),
dashboardBody(h3("example"),
mainPanel( shinyjs::useShinyjs(),
tabsetPanel(type = "tab",
tabPanel(h5("1"), infoBox("a,1,1")),
tabPanel(h5("2"), infoBox("b,2,2")),
tabPanel(h5("Block wise"),
loadEChartsLibrary(),
tags$div(id="demo1",
style="width:100%;height:500px;"),
deliverChart(div_id="demo1"),
downloadButton("downloadData", "Download Data"),
actionButton("reset","reset plot")))))))
server <- shinyServer(function(input,output){
observeEvent(input$reset,{
shinyjs::runjs("location.reload();")
})
output$downloadData <- downloadHandler(
filename = function() {
paste('data-', Sys.Date(), '.csv', sep='')
},
content = function(con) {
write.csv(demo, con)
})
renderBarChart(div_id = "demo1", grid_left = '1%', direction =
"vertical", data = demo)})
shinyApp(ui,server)
我想在选择特征后重设绘图。 按下“ 重置图”按钮时,它会进入tabPanel中的第一个选项卡“ 1 ”,而不是默认将图重置为默认值。
在这个问题上的任何帮助都是非常有意义的。 单击“ 重置图”不应路由到选项卡面板“ 1 ”,并且应将图重置为默认图。
答案 0 :(得分:1)
只需将事件重置为此:
observeEvent(input$reset,{
renderBarChart(div_id = "demo1", grid_left = '1%', direction =
"vertical", data = demo)
})
您的代码正在重新设置整个光泽,如果我理解得很好,则只想重新设置情节。 请注意,如果您未发布真实代码,则您的真实应用将需要进行其他调整。